Logout - How to clear cache , asp.NET
I am working on an asp.NET 4.0 Web Application with C#. 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
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
protected void Page_Init(object sender, EventArgs e)
{
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
}
精彩评论