Reputation: 4076
I have a user control in my asp.net application that load it's data from cache. i want it's cache be updated when the value of a variable be changed so i put this code on page directive
<%@ OutputCache Duration="1000" VaryByParam="none"
VaryByControl="visitIsAu" %>
it works fine when i change the value of variable in markup like this
visitIsAu="true"
but it doesn't work when the value is changed through code behind like this
visitIsAu="<%=this.CurentUser.IsAuthorizedToVisitFiltered%>"
the value of variable does not change so its cache is not updated.
does anyone know why this happen?
Upvotes: 3
Views: 338
Reputation: 3485
For some reason I've never trusted the way ASP.NET handles cache using markup settings or using "injected" server tags on the aspx files. I know it works but it's only easy to control on simple scenarios.
I always implement cache control, when using user controls, at code behind level and taking into consideration that page life cycle that may have some catches base on the level of controls I have a certain page.
We can have: ascx > aspx or ascx > aspx > master.
In your case you need to guarantee that CurrentUser is set prior to the load of your user control. Check that using debug.
Upvotes: 1