ASP.NET Configuring Page-Level Caching
In this tutorial you will learn how to configure Page-Level Caching. Page directive and Duration attribute.
Configuring Page-Level Caching
1. In Visual Web Developer, switch to Design view.
2. Drag a Label control to your page, leaving the default name of Label1.
3. Switch to Design view.
4. Double-click the surface.
5. A stubbed out method will be created for you named Page_Load.
6. Add the following highlighted code to the method:
………………void Page_Load(Object sender, System.EventArgs e)
………………{
……………………….Label1.Text = System.DateTime.Now.ToString();
………………}
7. Press CTRL+F5 to run the page.
8. Close the browser.
Close the browser.9. Switch to Source view and add the following page directive beneath the @ Page directive:
< % @ OutputCache Duration="15" VaryByParam="none" % >
10. You are setting the page to be cached. The Duration attribute specifies that the page will remain in the cache for 15 seconds.
11. Press CTRL+F5 to run the page again.
12. Refresh the page several times.
13. Since the duration has been set to 15 seconds, the page is only refreshed after the lapse of that time.