JavaScript Editor jscript editor     Web designer 

Main Page

If your Web application contains a page that creates different output based on the type of the requesting browser, you can cache versions of page's output by the major version of the browser that requests the page. For example, when an Internet ExplorerВ 6 browser requests a page, one version of the page is cached. When a Netscape Navigator browser, another version of Internet Explorer, or any other browser requests the page, another version of the page is added to the output cache.


Major version and browser type information is passed through the MajorVersion property of the HttpBrowserCapabilities object in the current request. For more information, see How to: Detect Browser Types in ASP.NET Web Pages.

To cache multiple versions of a page declaratively based on browser type

  1. In the ASP.NET page, include an @ OutputCache directive with the required Duration and VaryByParam or VaryByControl attributes. The Duration attribute must be set to an integer greater than zero. If you want to cache only by browser type, set the VaryByParam attribute to "None".

  2. In the @ OutputCache directive, include the VaryByCustom attribute and set it to "browser".

    The following example will cause the page to be cached for 10 seconds. The output will vary by the browser type.

    В CopyCode imageCopy Code
    <%@ OutputCache Duration="10" VaryByParam="None" VaryByCustom="browser" %>

To cache multiple versions of a page programmatically based on browser type.

  1. In the page code, call the SetExpires and SetCacheability methods on the Cache property of the page's Response property.

  2. Call the SetVaryByCustom method, passing the value "browser" in the custom parameter.

    The following code example shows how to cache multiple versions of a page for one minute. The output will vary by the type of browser that made the request.

    C#В CopyCode imageCopy Code
    protected void Page_Load(object sender, EventArgs e)

    Visual BasicВ CopyCode imageCopy Code
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

See Also

JavaScript Editor jscript editor     Web designer