I have used Session.Abandon();
Session.Clear();
on Logout Button and redirected to Login page. BUT When i click on back button of the browser i still get back to back page.
我用过Session.Abandon(); Session.Clear();在“注销”按钮上,重定向到“登录”页面。但是,当我点击浏览器的后退按钮时,我仍然会返回到后面的页面。
2 个解决方案
#1
1
Because it is fetching page from cache, you may want to disable cache for those respective page.
因为它是从缓存中提取页面,所以您可能希望为这些相应页面禁用缓存。
Some people asks for disabling back button, it is not possible to disable back button. Alternatives are:
有些人要求禁用后退按钮,无法禁用后退按钮。替代方案是:
- Prevent Caching those page
- 防止缓存那些页面
- Prevent User from going back once user logs out of application.
- 用户退出应用程序后,防止用户返回。
For second case, check out the below code and put it in your login page.
对于第二种情况,请查看以下代码并将其放入登录页面。
<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>
and Call it like below:
并在下面调用它:
<body onload="changeHashOnLoad(); ">
//---Rest of your code
It will work in all the browser.
它适用于所有浏览器。
Source: SO (don't have link to the original thread)
来源:SO(没有原始主题的链接)
#2
0
You can use use like follows
您可以使用如下使用
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();
#1
1
Because it is fetching page from cache, you may want to disable cache for those respective page.
因为它是从缓存中提取页面,所以您可能希望为这些相应页面禁用缓存。
Some people asks for disabling back button, it is not possible to disable back button. Alternatives are:
有些人要求禁用后退按钮,无法禁用后退按钮。替代方案是:
- Prevent Caching those page
- 防止缓存那些页面
- Prevent User from going back once user logs out of application.
- 用户退出应用程序后,防止用户返回。
For second case, check out the below code and put it in your login page.
对于第二种情况,请查看以下代码并将其放入登录页面。
<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>
and Call it like below:
并在下面调用它:
<body onload="changeHashOnLoad(); ">
//---Rest of your code
It will work in all the browser.
它适用于所有浏览器。
Source: SO (don't have link to the original thread)
来源:SO(没有原始主题的链接)
#2
0
You can use use like follows
您可以使用如下使用
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();