Remove from user cache related data on Session_End

I am inserting something into the cache when the user makes a login.

Now I want to remove this from the cache when the user session expires. The HttpContext is null .. so I don't know which user the session expired for. How can I find this?

EDIT: unfortunately SessionID doesn't offer me much. What I am doing in this particular case is using an HttpModule that handles the AuthorizeRequest to insert the current username into the Cache to ensure that another user from a different computer cannot log in. But the session in the HttpModule is null. So I cannot use this. Any other suggestions?

+1


source to share


3 answers


You can go to the session in the HttpModule, you just have to wait until it is initialized, i.e. the AcquireRequestState event ( http://msdn.microsoft.com/en-au/system.web.httpapplication.acquirerequeststate.aspx )



+1


source


Handle the Session_End event in your global.asax. This is where you should be able to access the SessionID.



+1


source


Assuming you are accessing the cached element on every page, you can set a sliding ending for the cache element. Set the expiration time in the same way as the session timeout. With an expiration date, the cache will be refreshed every time the object is available and will be deleted if it is not accessed within that time.

See http://msdn.microsoft.com/en-us/library/4y13wyk9.aspx for details .

+1


source







All Articles