繁体   English   中英

如何在用户使用c#在asp.net中注销时清除浏览器缓存?

[英]How to clear browser cache when user log off in asp.net using c#?

作为asp.net中的新功能。 在我的asp.net应用程序中使用函数ClearSession() log off on click event成员身份,但是如果我在浏览器上单击后退按钮它将转发到缓存页面,则在注销后出现问题。 如何在浏览器中清除缓存,以便用户在未登录时无法查看其配置文件

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标头才能支持所有浏览器。 根据这篇关于SO的文章,这些是适用于所有浏览器的:

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应用程序,因此您应该向所有页面添加包含此标题的过滤器,或者您可以禁用后退按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM