WebClientProtocol.Credentials 속성

정의

XML Web services 클라이언트 인증의 보안 자격 증명을 가져오거나 설정합니다.

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

속성 값

ICredentials

XML Web services 클라이언트에 대한 ICredentials입니다.

예제

다음 예제는 라고 하는 XML 웹 서비스를 호출 하는 ASP.NET 웹 폼을 Math입니다. 내 합니다 EnterBtn_Click 함수 Web Form 인증 자격 증명을 사용 하 여 명시적으로 설정 합니다 Credentials 속성입니다. 사용자 이름, 암호 및 도메인에 대 한 생성자에 전달 되는 NetworkCredential 클래스입니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 다음을 참조하십시오.

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

<html>
    <script language="C#" runat="server">
       void EnterBtn_Click(Object Src, EventArgs E) 
          {
            MyMath.Math math = new MyMath.Math();
            
            // Obtain password from a secure store.
            String SecurelyStoredPassword = String.Empty; 
 
            // Set the client-side credentials using the Credentials property.
            ICredentials credentials = new NetworkCredential("Joe",SecurelyStoredPassword,"mydomain");
            math.Credentials = credentials;
       
            int total = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text));
            Total.Text = "Total: " + total.ToString();
         }
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>

<html>
    <script language="VB" runat="server">
        Sub EnterBtn_Click(src As Object, e As EventArgs)
            Dim math As New MyMath.Math()

            ' Obtain password from a secure store.
            Dim SecurelyStoredPassword As String = String.Empty
            
            ' Set the client-side credentials using the Credentials property.
            Dim credentials = New NetworkCredential("Joe", SecurelyStoredPassword, "mydomain")
            math.Credentials = credentials
            
            Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
            Total.Text = "Total: " + iTotal.ToString()
        End Sub
 
    </script>
 
    <body>
       <form action="MathClient.aspx" runat=server>
           
          Enter the two numbers you want to add and then press the Total button.
          <p>
          Number 1: <asp:textbox id="Num1" runat=server/>  +
          Number 2: <asp:textbox id="Num2" runat=server/> =
          <asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
          <p>
          <asp:label id="Total"  runat=server/>
          
       </form>
    </body>
 </html>

설명

사용 하는 경우는 Credentials 속성을 XML Web service 클라이언트를 구현 하는 클래스를 인스턴스화해야 ICredentials와 같은 NetworkCredential를 설정한 후 클라이언트 자격 증명 특정 인증 메커니즘에. NetworkCredential basic을 사용 하는 인증 자격 증명을 설정 하는 클래스를 사용할 수 있습니다 다이제스트, NTLM 및 Kerberos 인증 메커니즘입니다.

Credentials 속성이 CredentialCache.DefaultCredentials로 설정되면 클라이언트는 서버의 구성 방식에 따라 Kerberos 및 NTLM 인증을 수행하기 위해 서버와 협상합니다.

적용 대상

추가 정보