注销后的后退按钮问题 [英] Back button Issue after Logout
问题描述
我浏览了一些链接并花费了几个小时,但在点击返回按钮后,我的页面仍然会加载。这里是我注销的页面代码,我试过。
protected void Page_Load(object sender,EventArgs e)
{
if(Session [Constants.KeyValues.UserProfileSession] == null)
{
Response.Redirect(www.google.com,true);
}
////清除cookie并将用户重定向到登录页面(登录前着陆页面)。
Response.AddHeader(pragma,no-cache);
Response.AddHeader(cache-control,private);
Response.CacheControl =no-cache;
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
FormsAuthentication.SignOut();
Response.Cookies.Clear();
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
Session.Clear();
Session.Abandon();
Session [Constants.KeyValues.UserProfileSession] = null;
Response.Write(< script type = \text / javascript\> window.location.replace('www.google.com');< / script>);
//Response.Redirect(www.google.com,true);
}
这里是我的html页面
<!doctype html>
< html lang =ko>
< head>
< title>< / title>
< meta http-equiv =Cache-Controlcontent =no-cache/>
< meta http-equiv =Pragmacontent =no-cache/>
< meta http-equiv =Expirescontent =0/>
< script type =text / javascript>
函数ClearHistory(){
var backlen = history.length;
history.go(-backlen);
window.location.href = www.google.com
}
< / script>
< / head>
< body onload =ClearHistory();>
< / body>
< / html>
以下是登录后会员登录的页面加载代码
protected void Page_Load(object sender,EventArgs e)
{
if(Session [Constants.KeyValues.UserProfileSession] == null)
{
Response.Redirect(SPContext.Current.Site.Url +/_layouts/ABC/ShoppingLandingBeforeLogin.aspx,true);
}}
以下是我尝试过的链接。
Response.AppendHeader()>解决方案
尝试使用它,它适用于所有浏览器。 Cache-Control,no-cache,no-store,must-revalidate); // HTTP 1.1。
Response.AppendHeader(Pragma,no-cache); // HTTP 1.0。
Response.AppendHeader(Expires,0); //代理。
I have gone through some links and spend hours but My page still loads after log out on clicking back button. here is my log out page code which i tried.
protected void Page_Load(object sender, EventArgs e)
{
if(Session[Constants.KeyValues.UserProfileSession]== null)
{
Response.Redirect("www.google.com", true);
}
////Clear cookie and redirect user to login page (Landing page before login).
Response.AddHeader("pragma", "no-cache");
Response.AddHeader("cache-control", "private");
Response.CacheControl = "no-cache";
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
FormsAuthentication.SignOut();
Response.Cookies.Clear();
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
Session.Clear();
Session.Abandon();
Session[Constants.KeyValues.UserProfileSession] = null;
Response.Write("<script type=\"text/javascript\">window.location.replace('www.google.com');</script>");
//Response.Redirect("www.google.com", true);
}
here is my html page
<!doctype html>
<html lang="ko">
<head>
<title></title>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<script type="text/javascript">
function ClearHistory() {
var backlen = history.length;
history.go(-backlen);
window.location.href = www.google.com
}
</script>
</head>
<body onload="ClearHistory();">
</body>
</html>
Here is the code of the page load where member go after login
protected void Page_Load(object sender, EventArgs e)
{
if(Session[Constants.KeyValues.UserProfileSession]== null)
{
Response.Redirect(SPContext.Current.Site.Url + "/_layouts/ABC/ShoppingLandingBeforeLogin.aspx", true);
} }
Here are the links i have tried.
How to clear browser cache when user log off in asp.net using c#?,
How to prevent browser and proxy caching of web pages,
Browser back button issue after logout,
Clear History using javascript,
back-button-of-browser-issue-in-asp-net-logout
Try to use this, it works across all browsers.
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.
这篇关于注销后的后退按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!