【发布时间】:2014-10-22 02:07:23
【问题描述】:
我浏览了一些链接并花费了数小时,但在单击返回按钮注销后我的页面仍然加载。这是我尝试过的注销页面代码。
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);
}
这是我的html页面
<!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>
这是会员登录后页面加载的代码
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);
} }
这是我尝试过的链接。
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,
【问题讨论】:
-
这不是您需要更改的注销页面的可缓存性 - 这是您要返回的页面的可缓存性。该页面上的缓存标头是什么?
-
我不希望用户在退出后被重定向到会员页面。我无法禁用后退按钮,但可以清除浏览器的捕获。或任何其他方法来实现我的目标。
-
@Tim :我添加了当我们点击后退按钮时加载的页面代码。但是该页面来自缓存,因此无法检查会话空值。
-
@lovethakker 首次加载该页面时的缓存标头是什么?如果该页面被浏览器缓存,那么您在注销页面上设置的缓存标头无关紧要 - 它不会影响任何其他页面。
-
@Tim :我正在注销页面中的所有页面中添加元标记。但我仍然无法从缓存中删除它们。
标签: c# javascript jquery html asp.net