HttpWebClientProtocol.CookieContainer 속성

정의

쿠키의 컬렉션을 가져오거나 설정합니다.

public:
 property System::Net::CookieContainer ^ CookieContainer { System::Net::CookieContainer ^ get(); void set(System::Net::CookieContainer ^ value); };
public System.Net.CookieContainer CookieContainer { get; set; }
member this.CookieContainer : System.Net.CookieContainer with get, set
Public Property CookieContainer As CookieContainer

속성 값

CookieContainer

웹 서비스 클라이언트에 대한 쿠키를 나타내는 CookieContainer입니다.

예제

다음 코드 예제는 세션 상태를 사용 하는 XML 웹 서비스의 Web Forms 클라이언트. 클라이언트는 클라이언트의 세션 상태에 저장 하 여 세션을 고유 하 게 식별 하는 HTTP 쿠키를 저장 합니다.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>

<html>

    <script runat="server">

        void EnterBtn_Click(Object Src, EventArgs E) 
    {
      // Create a new instance of a proxy class for your XML Web service.
      ServerUsage su = new ServerUsage();
          CookieContainer cookieJar;

      // Check to see if the cookies have already been saved for this session.
      if (Session["CookieJar"] == null) 
        cookieJar= new CookieContainer();
          else
       cookieJar = (CookieContainer) Session["CookieJar"];

        // Assign the CookieContainer to the proxy class.
        su.CookieContainer = cookieJar;

      // Invoke an XML Web service method that uses session state and thus cookies.
      int count = su.PerSessionServiceUsage();         

      // Store the cookies received in the session state for future retrieval by this session.
      Session["CookieJar"] = cookieJar;

          // Populate the text box with the results from the call to the XML Web service method.
          SessionCount.Text = count.ToString();  
        }
         
    </script>
    <body>
       <form runat=server ID="Form1">
           
             Click to bump up the Session Counter.
             <p>
             <asp:button text="Bump Up Counter" Onclick="EnterBtn_Click" runat=server ID="Button1" NAME="Button1"/>
             <p>
             <asp:label id="SessionCount"  runat=server/>
          
       </form>
    </body>
</html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>

<html>

    <script runat=server>

        Public Sub EnterBtn_Click(src As Object, E As EventArgs) 

      ' Create a new instance of a proxy class for your XML Web service.
      Dim su As ServerUsage = new ServerUsage()
          Dim cookieJar As CookieContainer

      ' Check to see if the cookies have already been saved for this session.
      If (Session("CookieJar") Is Nothing) 
        cookieJar= new CookieContainer()
          Else
       cookieJar = Session("CookieJar")
      End If
   

        ' Assign the CookieContainer to the proxy class.
        su.CookieContainer = cookieJar

      ' Invoke an XML Web service method that uses session state and thus cookies.
      Dim count As Integer = su.PerSessionServiceUsage()         

      ' Store the cookies received in the session state for future retrieval by this session.
      Session("CookieJar") = cookieJar

          ' Populate the text box with the results from the call to the XML Web service method.
          SessionCount.Text = count.ToString()  
    End Sub
         
    </script>
    <body>
       <form runat=server ID="Form1">
           
             Click to bump up the Session Counter.
             <p>
             <asp:button text="Bump Up Counter" Onclick="EnterBtn_Click" runat=server ID="Button1" NAME="Button1"/>
             <p>
             <asp:label id="SessionCount"  runat=server/>
          
       </form>
    </body>
</html>

설명

XML 웹 서비스 메서드를 세션 상태를 사용 하는 경우 다음 쿠키 전달 다시 응답 헤더에 해당 XML 웹 서비스 클라이언트에 대 한 세션을 고유 하 게 식별 하는 XML 웹 서비스 클라이언트입니다. 클라이언트에 대 한 세션 상태를 유지 하기 위해 XML 웹 서비스에 대 한 순서 대로 클라이언트 쿠키를 저장 해야 합니다. 클라이언트의 새 인스턴스를 만들어 HTTP 쿠키를 받을 CookieContainer 에 할당 하 여 CookieContainer XML 웹 서비스 메서드를 호출 하기 전에 프록시 클래스의 속성입니다. 프록시 클래스 인스턴스 범위를 벗어날 경우 이외에 세션 상태를 유지 하는 경우 클라이언트는 XML 웹 서비스 호출 간에 HTTP 쿠키를 저장 해야 합니다. Web Forms 클라이언트 저장 하 여 HTTP 쿠키를 저장할 수 있습니다 예를 들어를 CookieContainer 자체 세션 상태에 있습니다. 세션 상태를 사용 하 여 모든 XML Web services 이므로 되므로 클라이언트는 항상 사용할 필요가 없습니다를 CookieContainer 클라이언트 프록시의 속성을 XML 웹 서비스에 대 한 설명서 해야 상태 세션 상태 사용 되는지 여부를 합니다.

적용 대상

추가 정보