当用户使用C#在ASP.NET中注销时,如何清除浏览器缓存



as as asp.net中的新。在我的ASP.NET应用程序中,在log off on click event中使用函数ClearSession()的会员资格中,但是如果我单击浏览器上的返回按钮,则在注销后出现问题,它正在转发到缓存的页面。如何清除浏览器中的缓存,以便用户无法查看其配置文件,如果他未登录

protected void ClearSession()
{
    FormsAuthentication.SignOut();
    Session.Clear();
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.ExpiresAbsolute = DateTime.UtcNow.AddDays(-1d);
    Response.Expires = -1500;
    Response.CacheControl = "no-Cache";
}

我想你几乎在那里。您需要更多的HTML标头来支持所有浏览器。根据这篇文章,这些是在所有浏览器上都可以使用的文章:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

为此的完整代码是:

HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache, no-store, must-revalidate");
HttpContext.Current.Response.AddHeader("Pragma", "no-cache");
HttpContext.Current.Response.AddHeader("Expires", "0");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache"); 
response.setDateHeader("Expires", 0); 

这些标头只能在不包含所有Web应用程序的页面上工作,因此您要么添加包含此标头的过滤器,要么将标头包含到所有页面。

最新更新