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

Has*_*aan 5 c# asp.net cache-control

作为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";
}
Run Code Online (Sandbox Code Playgroud)

Pat*_*man 9

我想你差不多了.您需要更多HTML标头才能支持所有浏览器.根据这篇关于SO的文章,这些是适用于所有浏览器的:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Run Code Online (Sandbox Code Playgroud)

完整的代码是:

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");
Run Code Online (Sandbox Code Playgroud)