다음을 통해 공유


Substitution.MethodName 속성

정의

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

속성 값

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를 참조하세요.

적용 대상

추가 정보