You can vary by browser the output cache for pages using two techniques; only the
@OutputCache
directive is supported for User Control caching:
<%@OutputCache Duration="60" VaryByParam="none"
VaryByCustom="browser" %>
[content]
or
<script runat="server">
' Note, this only works for pages and not user controls
Sub Page_Load(object As Sender, e As EventArgs)
Response.Cache.SetExpires(DateTime.Now.AddSeconds(100))
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.Cache.SetValidUntilExpires(true)
Response.Cache.SetVaryByCustom("browser")
End Sub
</script>
[content]
Comments
ASP.NET server controls can render different content depending upon the user/agent
presented to the server during the request. All browsers present a user/agent that allows
the server addressing the request to know the capabilities of the browser.This is regardless
of whether the browsers are desktop browsers such as IE, Netscape, or Opera, or
mobile/device browsers, such as the browser found in a RIM device, cellular phone, or
handhelds.
Many ASP.NET server controls can render different content that is better suited to
the browser type making the request. A great example of this capability is existence of IE
Web Controls and ASP.NET Mobile controls (both available at www.asp.net).These
controls intelligently detect the browser type.When desktop browsers are used, HTML is
rendered.When mobile browsers are used,WML is rendered.
Varying the cache by browser allows for the ASP.NET cache to store different versions
of the requested page in the cache based on the type of browser making the
request.The only caveat is that only the browser type and major version number-IE
6.0, for example-are tracked. For example, versions 4.0, 4.1, and 4.5, of Netscape
browsers would all resolve to one entry within the cache.
No comments:
Post a Comment