2012-04-26 52 views
1

我想问一下关于注销后失去了本届会议:会议在ASP.Net(C#)在Firefox和Chrome

我写的代码,但它仅在Internet Explorer中的工作,而不是在Mozilla Firefox或谷歌铬。在这两种浏览器中,如果我点击后退按钮进行注销,则会返回用户的帐户。

注销页面代码(在页面加载) -

FormsAuthentication.SignOut(); 
Session.Abandon(); 
Session["CustomerId"] = null; 
FormsAuthentication.RedirectToLoginPage(); 

在其他每一页或主PAGE-

Response.Cache.SetCacheability(HttpCacheability.NoCache); 
if (Session["CustomerId"] == null) 
{ 
    Response.Redirect("~/Login.aspx"); 
} 

在web的配置文件 -

<authentication mode="Forms"> 
    <forms name="MyCookie" loginUrl="Login.aspx" protection="All" timeout="90" slidingExpiration="true"></forms> 
</authentication> 
+1

但是你还在登录吗?如果你点击后退按钮,浏览器可能会返回一个缓存页面。如果您尝试使用Ctrl + F5重新加载页面,您是否仍然登录? – sirrocco 2012-04-26 10:45:38

回答

3

如果你按回来,即使用户注销,你仍然可以看到用户信息,是因为你没有照顾缓存浏览器,所以该网页未被浏览器缓存。

要你不希望留在浏览器缓存,你需要设置的所有页面:

CurrentPage.Response.Cache.SetExpires(DateTime.UtcNow.AddYears(-4)); 
CurrentPage.Response.Cache.SetValidUntilExpires(false); 
CurrentPage.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
CurrentPage.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
CurrentPage.Response.Cache.SetNoStore(); 
CurrentPage.Response.ExpiresAbsolute = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)); 
CurrentPage.Response.Expires = 0; 
CurrentPage.Response.CacheControl = "no-cache"; 
CurrentPage.Response.AppendHeader("Pragma", "no-cache"); 
CurrentPage.Response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate, post-check=0, pre-check=0"); 

既然IE不保存数据,以及其他让他们的理由是因为安装的每个浏览器选择工作,或者你已经设置。这里的要点是,如果您想避免将此数据保存在浏览器缓存中,则必须拥有该控件并且不要让浏览器使用默认设置。

单独使用HttpCacheability.NoCache也许足够用于一个浏览器,但对于所有浏览器来说都不够。此外,它更好地使用SSL,因为此页面可能会被代理缓存在路上...

1

您需要检查Page_init()事件上的用户会话。如果会话为空,则将用户重定向到登录页面。所以如果你注销然后尝试点击后退按钮,那么系统会将用户重定向到登录页面而不是该用户帐户。

这是事件,你需要检查用户会话,

protected void Page_init(object sender, EventArgs e) 
    { 
     if (Session["User"] == null) 
     { 
      Response.Redirect("Login.aspx"); 
     } 
    } 

希望这会帮助你。 谢谢。