[英]Logout - How to clear cache , asp.NET
I am working on an asp.NET 4.0 Web Application with C#. 我正在使用C#开发一个ASP.NET 4.0 Web应用程序。 I am currently authentication with the use of sessions, and on logout I am clearing the session.
我目前正在使用会话进行身份验证,并且在注销时正在清除会话。 However there is a problem when the user presses back, he is still able to see the cached page.
但是,当用户按回去时仍然存在问题,他仍然可以看到缓存的页面。 I would like to disable caching, of such pages, or make sure that it is checked for.
我想禁用此类页面的缓存,或者确保对其进行检查。
What is the best way of doing this? 最好的方法是什么? If I set the server to not store cached information, will this effect all the applications or will it just be my application?
如果我将服务器设置为不存储缓存的信息,这会影响所有应用程序还是仅仅是我的应用程序?
Add this in page_load
在
page_load
添加
Response.Cache.SetCacheability(HttpCacheability.NoCache);
This is the only true answer although it's important to know that it's only a request to the browser to stop caching - it doesn't necessarily have to follow. 这是唯一的真实答案,尽管重要的是要知道这只是浏览器停止缓存的请求 -不一定要遵循。
This needs to be included on every page you don't want the user to 'back button' onto. 这需要包含在您不希望用户“后退按钮”进入的每个页面上。
You can add following lines in Page_Init of Master page 您可以在母版页的Page_Init中添加以下行
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.