WebRequest.AuthenticationLevel WebRequest.AuthenticationLevel WebRequest.AuthenticationLevel WebRequest.AuthenticationLevel Property

定義

この要求で使用する認証レベルおよび偽装レベルを示す値を取得または設定します。Gets or sets values indicating the level of authentication and impersonation used for this request.

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 値のビットごとの組み合わせ。A bitwise combination of the AuthenticationLevel values. 既定値は MutualAuthRequested です。The default value is MutualAuthRequested.

相互認証では、クライアントとサーバーの両方が、それらの身元を証明する資格情報を提供します。In mutual authentication, both the client and server present credentials to establish their identity. MutualAuthRequiredMutualAuthRequested は、Kerberos 認証に関連する値です。The MutualAuthRequired and MutualAuthRequested values are relevant for Kerberos authentication. Kerberos 認証は、直接サポートすることも、Negotiate セキュリティ プロトコルを使用して実際のセキュリティ プロトコルを選択する場合に使用することもできます。Kerberos authentication can be supported directly, or can be used if the Negotiate security protocol is used to select the actual security protocol. 認証プロトコルの詳細については、「インターネット認証」を参照してください。For more information about authentication protocols, see Internet Authentication.

相互認証が行われたかどうかを確認するには、IsMutuallyAuthenticated プロパティをチェックします。To determine whether mutual authentication occurred, check the IsMutuallyAuthenticated property.

MutualAuthRequired 認証フラグの値を指定していて相互認証が行われない場合、アプリケーションは、相互認証が失敗したことを示す ProtocolViolationException 内部例外を持つ IOException を受け取ります。If you specify the MutualAuthRequired authentication flag value and mutual authentication does not occur, your application will receive an IOException with a ProtocolViolationException inner exception indicating that mutual authentication failed.

次のコード例では、このプロパティの値を設定します。The following code example sets the value of this property.

// 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();
}

適用対象