Substitution.MethodName 属性
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置要在 Substitution 控件执行时调用的回调方法的名称。
public:
virtual property System::String ^ MethodName { System::String ^ get(); void set(System::String ^ value); };
public virtual string MethodName { get; set; }
member this.MethodName : string with get, set
Public Overridable Property MethodName As String
字符串,表示要在 Substitution 控件执行时调用的方法的名称。
下面的代码示例演示如何以声明方式将控件添加到 Substitution 输出缓存网页。 加载页面时,向用户显示静态项目符号列表。 页面的此部分仅每 60 秒缓存并更新一次。 控件 Substitution 执行时,它会调用 GetUser
方法,该方法返回表示当前用户的字符串。 此字符串显示在页面上控件 Substitution 的位置。 页面的这一部分不会缓存,每次刷新页面时都会更新。
<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#">
// The Substitution control calls this method to retrieve
// the name of the current user from the HttpContext object.
// This section of the page is exempt from output caching.
public static string GetUser(HttpContext context)
{
return context.User.Identity.Name;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Substitution.MethodName Property Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>Substitution.MethodName Property Example</h3>
<!--This section of the page is not cached.-->
Welcome to the site,
<asp:substitution id="Substitution1"
methodname="GetUser"
runat="Server">
</asp:substitution>
<br /><br />
<!--This section of the page is cached.-->
Product list:
<asp:bulletedlist id="ItemsBulletedList"
displaymode="Text"
runat="server">
<asp:ListItem>Product 1</asp:ListItem>
<asp:ListItem>Product 2</asp:ListItem>
<asp:ListItem>Product 3</asp:ListItem>
</asp:bulletedlist>
</form>
</body>
</html>
<%@ outputcache duration="60" varybyparam="none" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="VB">
' The Substitution control calls this method to retrieve
' the name of the current user from the HttpContext object.
' This section of the page is exempt from output caching.
Shared Function GetUser(ByVal context As HttpContext) As String
Return context.User.Identity.Name
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Substitution.MethodName Property Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>Substitution.MethodName Property Example</h3>
<!--This section of the page is not cached.-->
Welcome to the site,
<asp:substitution id="Substitution1"
methodname="GetUser"
runat="Server">
</asp:substitution>
<br /><br />
<!--This section of the page is cached.-->
Product list:
<asp:bulletedlist id="ItemsBulletedList"
displaymode="Text"
runat="server">
<asp:ListItem>Product 1</asp:ListItem>
<asp:ListItem>Product 2</asp:ListItem>
<asp:ListItem>Product 3</asp:ListItem>
</asp:bulletedlist>
</form>
</body>
</html>
MethodName使用 属性指定要在执行控件时调用的Substitution回调方法的名称。 指定的回调方法必须是包含 Substitution 该控件的页面或用户控件上的静态方法。 回调方法的签名必须与接受HttpContext参数并返回字符串的委托的签名HttpResponseSubstitutionCallback匹配。 回调方法返回的字符串是页面上控件位置 Substitution 上要显示的内容。
参数 HttpContext 封装有关单个 HTTP 请求的所有特定于 HTTP 的信息。 可以使用它来访问会话变量、授权信息和个性化设置详细信息。 有关详细信息,请参阅 HttpResponseSubstitutionCallback。
产品 | 版本 |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |