关于asp.net2.0中缓存页面的部分数据(Request.UserHostAddress.ToString(),就是客户端的IP不同反映的欢迎信息不同)需要实时变化的问题想在一个页面中,只把Request.UserHostAddress.ToString()实时显示,并且输出到页面上,其他的内容都缓存起来,任何浏览用户看的都是一样。请问应该怎么设置?谢谢大家!

解决方案 »

  1.   

    补充一下,为了移植方便,而且内容在不同的页面有变化,所以不能用
    web 用户控件来解决。最好在.aspx 或者 .CS中解决。
      

  2.   

    <%@ outputcache duration="60" varybyparam="none" %>
    <script runat="server" language="C#">  
      
      void Page_Load(object sender, System.EventArgs e)
      {
        // Programmatically create a Substitution control.
        Substitution Substitution1 = new Substitution();
        
        // Specify the callback method.
        Substitution1.MethodName = "GetCurrentDateTime";
        
        // Add the Substitution control to the controls
        // collection of PlaceHolder1.
        PlaceHolder1.Controls.Add (Substitution1);            // Display the current date and time in the label.
        // Output caching applies to this section of the page.
        CachedDateLabel.Text = DateTime.Now.ToString();    
      }
      
      // The Substitution control calls this method to retrieve
      // the current date and time. This section of the page
      // is exempt from output caching. 
      public static string GetCurrentDateTime (HttpContext context)
      {
        return DateTime.Now.ToString ();
      }
      
    </script><html>
    <head id="Head1" runat="server">
      <title>Substitution Class Example</title>
    </head>
    <body>
      <form id="Form1" runat="server">
      
        <h3>Substitution Constructor Example</h3>  
        
        <p>This section of the page is not cached:</p>
        <asp:placeholder id="PlaceHolder1"
          runat="Server">
        </asp:placeholder>
        
        <br />
        
        <p>This section of the page is cached:</p>
        
        <asp:label id="CachedDateLabel"
          runat="Server">
        </asp:label>
        
        <br /><br />
        
        <asp:button id="RefreshButton"
          text="Refresh Page"
          runat="Server">
        </asp:button>       </form>
    </body>
    </html>已经解决谁来接分。