ASP.net: Cache problem when logout

asp.net

I can't find any post regarding the cache on logout so I'm going to ask this question. If there is a similar question. Please let me know.

I have a Logout page that basically call FormAuthentications signout method then redirect the user to the login page. It work fine but the problem is user can click on the browser's back button and get the cached page. I tried to set the no-cache header on my master page but that doesn't work.

Can someone point me to a article or tutorial or post some tips on how you handle this situation?

thank

Best Answer

Depending on your requirements a possible solution might be to set the Cache-Control header to "no-cache" on every authenticated page. This will prevent pages from being cached downstream. It could be achieved by writing a custom HttpModule that will set the header:

// Prevent the browser from caching the ASPX page
Response.Cache.SetNoStore();

You can also set this in your page's HEAD section by adding the following line of code:

<meta http-equiv="Cache-Control" content="no-cache" />

By doing that if a user clicks the Back button once he's been signed out, he will be redirected to the login form instead of seeing a cached version of his last page which could be a problem if he is using a public computer.

Related Topic