我正在 ASP.NET (Framework 4.0) 中创建一个网站。我在这个网站上保持 session 。我已经编写了用于注销的代码,其中 FormsAuthentication 的 session 值为 Abandon 。我的代码如下用于注销按钮单击。
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Request.Cookies["ASP.NET_SessionId"] != null)
{
Response.Cookies["ASP.NET_SessionId"].Value = string.Empty;
Response.Cookies["ASP.NET_SessionId"].Expires = DateTime.Now.AddMonths(-20);
}
FormsAuthentication.SignOut();
Session.Abandon();
Response.Redirect(FormsAuthentication.DefaultUrl);
}
如何在注销和不使用 javascript 时禁用/阻止/阻止到上一页。因为当用户注销时,他重定向到默认页面,但用户单击浏览器后退按钮他重定向到上一页(即用户主页)而不是登录页面。
请您参考如下方法:
我认为您必须使用 javascript 。如果您使用的是母版页,则将此代码写在标题部分。
<script type="text/javascript">
window.history.forward(-1);
</script>
并在母版页 (Page_Load) 模式下编写此代码。
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
