1

Session.Abandon(); Session.Clear();ログアウトボタンで使用し、ログインページにリダイレクトしました。しかし、ブラウザの戻るボタンをクリックすると、まだ戻るページに戻ります。

4

2 に答える 2

1

キャッシュからページを取得しているため、それぞれのページのキャッシュを無効にすることができます。

戻るボタンを無効にするよう求める人もいますが、戻るボタンを無効にすることはできません。代替手段は次のとおりです。

  • それらのページをキャッシュしないようにする
  • ユーザーがアプリケーションからログアウトすると、ユーザーが戻らないようにします。

2 番目のケースでは、以下のコードを確認して、ログイン ページに配置します。

<script type = "text/javascript" >
function changeHashOnLoad() {
 window.location.href += "#";
 setTimeout("changeHashAgain()", "50"); 
}

function changeHashAgain() {
 window.location.href += "1";
}

var storedHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != storedHash) {
     window.location.hash = storedHash;
}
}, 50);


 </script>

以下のように呼び出します。

<body onload="changeHashOnLoad(); ">
 //---Rest of your code

すべてのブラウザで動作します。

出典:SO(元のスレッドへのリンクはありません)

于 2013-03-30T10:34:18.443 に答える
0

次のように使用できます

FormsAuthentication.SignOut();
Session.Abandon();

 // clear authentication cookie
 HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
 cookie1.Expires = DateTime.Now.AddYears(-1);
 Response.Cookies.Add(cookie1);

// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)

HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);

FormsAuthentication.RedirectToLoginPage();
于 2013-03-30T10:36:26.457 に答える