WebRequest.AuthenticationLevel 속성

정의

이 요청에 사용되는 인증 및 가장 수준을 나타내는 값을 가져오거나 설정합니다.

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

속성 값

AuthenticationLevel

AuthenticationLevel 값의 비트 조합입니다. 기본값은 MutualAuthRequested입니다.

상호 인증에서는 클라이언트와 서버가 모두 자격 증명을 제공해야 ID를 구성할 수 있습니다. MutualAuthRequiredMutualAuthRequested 값은 Kerberos 인증과 관련이 있습니다. Kerberos 인증은 직접 지원될 수도 있고, 보안 협상 프로토콜을 사용하여 실제 보안 프로토콜을 선택하는 경우에 사용할 수도 있습니다. 인증 프로토콜에 대 한 자세한 내용은 참조 하세요. 인터넷 인증합니다.

상호 인증이 발생했는지 여부를 확인하려면 IsMutuallyAuthenticated 속성을 확인합니다.

MutualAuthRequired 인증 플래그 값을 지정할 경우 상호 인증이 발생하지 않으면 애플리케이션에서는 상호 인증이 실패했음을 나타내는 내부 예외인 ProtocolViolationException과 함께 IOException이 발생합니다.

예제

다음 코드 예제에서는이 속성의 값을 설정합니다.

// The following example uses the System, System.Net, 
// and System.IO namespaces.
static void RequestMutualAuth( Uri^ resource )
{
   // Create a new HttpWebRequest object for the specified resource.
   WebRequest^ request = dynamic_cast<WebRequest^>(WebRequest::Create( resource ));

   // Request mutual authentication.
   request->AuthenticationLevel = AuthenticationLevel::MutualAuthRequested;

   // Supply client credentials.
   request->Credentials = CredentialCache::DefaultCredentials;
   HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());

   // Determine whether mutual authentication was used.
   Console::WriteLine( L"Is mutually authenticated? {0}", response->IsMutuallyAuthenticated );

   // Read and display the response.
   Stream^ streamResponse = response->GetResponseStream();
   StreamReader^ streamRead = gcnew StreamReader( streamResponse );
   String^ responseString = streamRead->ReadToEnd();
   Console::WriteLine( responseString );

   // Close the stream objects.
   streamResponse->Close();
   streamRead->Close();

   // Release the HttpWebResponse.
   response->Close();
}

// The following example uses the System, System.Net,
// and System.IO namespaces.

public static void RequestMutualAuth(Uri resource)
{
    // Create a new HttpWebRequest object for the specified resource.
    WebRequest request=(WebRequest) WebRequest.Create(resource);
    // Request mutual authentication.
   request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
    // Supply client credentials.
    request.Credentials = CredentialCache.DefaultCredentials;
    HttpWebResponse response = (HttpWebResponse) request.GetResponse();
    // Determine whether mutual authentication was used.
    Console.WriteLine("Is mutually authenticated? {0}", response.IsMutuallyAuthenticated);
    // Read and display the response.
    Stream streamResponse = response.GetResponseStream();
    StreamReader streamRead = new StreamReader(streamResponse);
    string responseString = streamRead.ReadToEnd();
   Console.WriteLine(responseString);
    // Close the stream objects.
    streamResponse.Close();
    streamRead.Close();
    // Release the HttpWebResponse.
    response.Close();
}

적용 대상