Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The important thing to note here is that if your VaryByCustom changes, asp.net stores a separate cached version of the page. </p> <p>So, supposing your VaryByCustom-"custom1" with Duration="60" then this will be cached for 60 seconds. </p> <p>In between if your VaryByCustom changes to "custom2" with duration="60" asp.net will store a separate copy in the cache, which is different from the cache of "custom1" and this separate version will be cached for 60 seconds. </p> <p>An easy way to test this is by changing VaryByCustom based on browser. </p> <p>In Global.asax</p> <pre><code>public override string GetVaryByCustomString(HttpContext context, string custom) { if (custom == "browser") { string browserName; browserName = Context.Request.Browser.Browser; browserName += Context.Request.Browser.MajorVersion.ToString(); return browserName; } else { return base.GetVaryByCustomString(context, custom); } } </code></pre> <p>Aspx</p> <pre><code>&lt;%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebFormsPlayGround._Default" %&gt; &lt;%@ OutputCache Duration="40" VaryByParam="None" VaryByCustom="browser" %&gt; </code></pre> <p>Page load</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { lblTime.Text = "The time now is: &lt;br/&gt;"; lblTime.Text += DateTime.Now.ToString(); } </code></pre> <p>I havent included the markup for asp:Label in the aspx, but I hope you get the general idea.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload