Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I currently have some code which creates a cache item when a user signs into the application.

I would like to know how would i be able to remove this cached item if the user closes the browser without signing out?
Posted

1 solution

You cannot handle the close button event consistently across many browsers.
As a result, it may be best to set an expiry on cache data.
For e.g.when you logon, you could set the cache expire to 30.
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(30));

Another approach could be to have a logout button and add the following code -
C#
Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
 Response.Cache.SetCacheability(HttpCacheability.NoCache);
 Response.Cache.SetNoStore();
 
Share this answer
 
Comments
isi19 29-Jul-14 6:02am    
I have added a session timeout to the application, the problem i am having is when the user closes the browser accidentally, they will then only be able to login once the cache timesout

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900