I ran into an issue that I can’t seem to fix, or even get around. In my View, I have the following:
@Html.Hidden("IsLocked", (Session["IsLocked"]) ? "true" : "")
The Session[“IsLocked”] variable is set in my BaseController, which all of the other controllers inherit from. However, I have found that if I visit a page, and it is not currently locked, and perform the lock operation and revisit it, it will not change the value of “IsLocked”.
I can’t seem to figure out why it isn’t changing, even though the Session value has changed?
It sounds like you are running into a caching issue, as the pages are being cached with their initial value and despite the value changing, when the page is requested it will simply pull from the cache.
You can use the OutputCache Attribute, to assist with disabling caching for these purposes. The following will ensure that your actions / pages are not cached and that data is always “fresh”:
The above can be placed over any controller or action to disable caching for that particular event. (In the above context, if placed on the BaseController, it would effectively disable caching for every controller that derives from BaseController)