Cache a user control based on a Property in the code behind.

M

MattC

I have a user control that is placed on every page to provide a menu system,
logout/login buttons etc.

This contect varies in depending on the value of a property in the code
behind file of the control.

How can I cache dependant on the value of that property.

TIA

MattC
 
M

MattC

This only gives examples of caching based on properties in the ASPX page I
would like to know if I can cache based on the value of a Code Behind
Property.
 
M

MattC

I have managed to cache based on a code behind property now but it seems to
not work how I would expect. I have this in my control.
<%@ OutputCache VaryByControl="UserType" Duration="300"%>

in my code begind is a property:

protected string UserType
{
get
{
if(SecurityHandler.ThisUser != null)
_usertype =
SecurityHandler.ThisUser.UserSecurityProfile.SecurityProfileName;

return _usertype;
}
}

UserType will return either Admin, String.Empty, Finance, User.

However when I visit a page it is cached but if I log out and log in as an
account with a different usertype i get the cached copy for the previous
user type, instead of what I expected was ASP.NET to cache a new version for
the new type. It seems the cache the control by the page not by the value
in the property.

TIA

MattC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top