Substitution page caching without caching

Source: Internet
Author: User

File 1: Deafault. aspx
Copy codeThe Code is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<% @ Outputcache duration = "10" varybyparam = "none" %>

<! -- Set the cache time to 10 seconds -->

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "">

<Head id = "Head1" runat = "server">
<Title> Substitution control instance </title>
<Form id = "Form1" runat = "server">

<H1> Substitution control instance demonstration Hello <B>
<Asp: substitution id = "m1" methodname = "GetUser" runat = "Server">
</Asp: substitution> </B> <br>
Current time [non-Cache]:

<B> <asp: Substitution ID = "m2" runat = "server" MethodName = "GetTime"/> </B>
Cache: <% = DateTime. Now. ToLongTimeString () %>
<Asp: Button ID = "Button1" runat = "server" Text = "refresh"/>

File 2: Deafault. aspx. cs
Copy codeThe Code is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;

Public partial class _ Default: System. Web. UI. Page

// The following two statement methods are defined. You can use the Substitution control to call these two methods each time they are refreshed.

Public static string GetUser (HttpContext context)
Return context. User. Identity. Name;
Public static String GetTime (HttpContext context)
Return DateTime. Now. ToString ();

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: 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.