Page Output Caching

You will now add a new page to your project that supports Page Output Caching.

1.  Add a new Web Form to your project, naming it "PageOutputCaching.aspx". In the Add New Item dialog make sure to check Place code in separate file and Select Master Page, selecting MasterPage.master.

2.  Open Web.sitemap and add another siteMapNode child element so that "Page Output Caching" appears in the navigation menu.

3. Click the PageOutputCaching.aspx tab and then click Design. Select the Content control, press F4, and then change the (ID) property to "bodyContent". In the Content control type "Page Output Caching", highlight it, and then from the Block Format toolbar menu, select Heading 2 <H2>. Finally, in the Content control type "Timestamp: ", and then drag a Label control to the design surface, changing its ID property to "timestampLabel".

4. Double-click anywhere on the gray area to add a Page Load event handler. To the handler add the following code, which sets the Label control's Text property to display the date and time that the page loaded:


timestampLabel.Text = DateTime.Now.ToString
VB

5. Click the PageOutputCaching.aspx tab and then click Source. Add the following OutputCache directive below the Page directive, effectively caching the page's contents for ten seconds: <%@ OutputCache VaryByParam="none" Duration="10" %>.

6. Press F5 to run the application. When the page loads, note the time and then press F5 continually until you see the time change approximately 10 seconds later.

 

As you can see, cached page contents were served until the cache expired, at which time new page contents were served.  

 
HyperLink HyperLink

Powered By ASP.NET v2.0