Application of subsitution in ASP. net2.0

Source: Internet
Author: User

We add a page to the website built in vs. net2005, drag a subsitution from the toolbox to the page, and write: getcurrenttime in the methodname on its property panel.

In the source file header of this ASPX page, add:

<% @ Outputcache duration = "30" varybyparam = "NONE" %>

This means that this page uses the output cache, And the cache duration is 30 seconds.

Then we can write this method in the background file:

Public static string getcurrenttime (httpcontext context)

{

Return datetime. Now. tostring ();

}

Note that the static keyword must be used here, because the subsitution Cache control only supports static methods, and the parameter can only be httpcontext. Note that no errors will occur.

Okay, now we run the page, and the page will display the time displayed. we refresh the page and the display time has changed. That is to say

No cache is used here. Of course, if you do not believe it, you can also drag a label into the page, and then in the background page_load

Write in method:

Label1.text = datetime. Now. tostring ();

Then run again. At the beginning, the two times displayed on the page are the same, both of which are the current time. However, after refreshing the page again, we can see that, the time on the subsitution Cache control is changed to the current time, while the time on label1 is not changed or the time when we opened the page, that is,Code: <% @ Outputcache duration = "30" varybyparam = "NONE" %> the cache is used on label1. The time above label1 will not change within 30 seconds.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.