0

asp.net 2005 でロール認証のサンプルを作成しました。default.aspx ページにログイン パネルを作成し、ログイン後に正常に動作しました。ログインには以下のコードを使用しました

FormsAuthentication.RedirectFromLoginPage(txtUName.Text, true, urlpath);
FormsAuthentication.SetAuthCookie(txtUName.Text, true);
Response.Redirect(urlpath, false);

ログイン後に表示される 1 つのマスター ページで、必要なすべてのページ リンクを使用しました。リンクボタンをクリックすると、以下のようにマスターページのコードを「ログアウト」に使用しました

 try
 {
      Response.Redirect("~/Logout.aspx" );
 }
 catch (Exception ee)
 { 
      return;
 }

マスターページからログアウトすると、このようなエラーが発生しました

unable to evaluate expression because the code is optimized or native frame is on top of call stack

ゴーグルしましたが、解決策がありません。この背後にある理由を見つけることができません。適切な解決策を提供してください。ありがとう

4

1 に答える 1

2
http://support.microsoft.com/kb/312629/en-us

この問題を回避するには、次のいずれかの方法を使用します。 • Response.End の場合、Response.End の代わりに HttpContext.Current.ApplicationInstance.CompleteRequest メソッドを呼び出して、コード実行を Application_EndRequest イベントにバイパスします。

• Response.Redirect の場合、endResponse パラメータに false を渡すオーバーロード Response.Redirect(String url, bool endResponse) を使用して、Response.End への内部呼び出しを抑制します。例: Response.Redirect ("nextpage.aspx", false);

この回避策を使用すると、Response.Redirect に続くコードが実行されます。• Server.Transfer の場合は、代わりに Server.Execute メソッドを使用します。

于 2013-01-10T07:35:34.163 に答える