For example, a website has a header. the ascx user control. Each page calls this control as the "page header". You can directly cache this user control to submit the performance. However, the current header. to display the login name of the login user, the ascx user control cannot directly use the following cache method:
<%
@ Outputcache duration
=
"
86400
"
Varybyparam
=
"
None
"
%>
In this case, you can use the "cache pages based on custom strings" method as follows:
<% @ Outputcache duration = " 86400 " Varybyparam = " None " Varybycustom = " Headerpagekey " %>
Then override the getvarybycustomstring method in the global class.
Public Override String Getvarybycustomstring (httpcontext context, String Custom)
{
If (Custom = " Headerpagekey " )
{
// Cache header. ascx Control
If (Context. Request. isauthenticated)
{
Return Context. User. Identity. Name;
}
Else
{
Return " Noauthenticated_user " ;
}
}
Return Base . Getvarybycustomstring (context, custom );
}
If the user does not log on, a version is cached. if the user has logged on, another version is cached Based on the login name. Haha, a version is cached for each user. In this way, it should be said that it is not a good solution.
The above cache technology can refer to the http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/cpguide/html/cpconcachingversionsofpagebasedonparameters. asp
In addition, this cache method is also used in mspetshop3.0. Different versions are cached based on request. querystring and whether to log on to the cache. However, this cache does not seem to be enabled by default.