Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Caching - Programatically Invalidating Server Cache...confusion on example
    text
    copied!<p>I'm reading how to programmatically invalidate cached pages on the server in ASP.NET, and the book ("MCTS Self-Paced Traing Kit (Exam 70-515)") says:</p> <blockquote> <p>To directly control whether a cached version of a page is used or whether the page is dynamically generated, response to the ValidateCacheOutput event and set a valid value for the HttpValidationStatus attribute.</p> </blockquote> <p>The code segments look like the following:</p> <pre><code>public static void ValidateCacheOutput(HttpContext context, Object data, ref HttpValidationStatus status) { if (context.Request.QueryString["Status"] != null) { string pageStatus = context.Request.QueryString["Status"]; if (pageStatus == "invalid") status = HttpValidationStatus.Invalid; else if (pageStatus == "ignore") status = HttpValidationStatus.IgnoreThisRequest; else status = HttpValidationStatus.Valid; } else status = HttpValidationStatus.Valid; } protected void Page_Load(object sender, EventArgs e) { Response.Cache.AddValidationCallback( new HttpCacheValidateHandler(ValidateCacheOutput), null); } </code></pre> <p>Could someone please explain to me what this code is doing? Also, the main question I have is that I thought Cached pages were simply returned from the server, but the code below indicates that the page life-cycle is being invoked (Page_Load event); I'm confused because the page life-cycle isn't invoked if a cached page is returned, so how would the code in the Page_Load event even fire?</p> <p>Note: Here's the <a href="http://msdn.microsoft.com/en-us/library/a5e5hdyz.aspx" rel="nofollow">same example</a> that the book has</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