简体   繁体   中英

ASP.NET page caching and session variable

I have a asp.net webpage that displays a link Login or Logout depending on a session variable "IsLogged". I want to implement caching in that page. But after applying caching the Login/Logout becomes inconsistent with the session variable. What is the best approach to address this problem so that I can also apply caching in that page?

Thanks, Partha

I am not sure how you are caching specifically but you could break your page up into two user controls (ascx).

Your aspx page could contain the user control to that shows the login information (make sure that when you load the user control with a dynamic url so that the caching ignores it because the address is diff everytime like:

yourSessionInfo.ascx?stopcache=32487239875 (the number could be just current time in ticks)

You just need something that changes in your url so that the page 'looks' like it is different and reloads.

Then have the rest of your page in another user control that has a static url:

yourRestOfPage.asx

Notice nothing changing in the url so page can be cached.

Not sure if this will solve your exact problem but it should at least start you down the right path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM