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

Définition

Obtient ou définit des valeurs indiquant les niveaux d'authentification et d'emprunt d'identité utilisés pour cette demande.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

Valeur de propriété

Combinaison d'opérations de bits des valeurs AuthenticationLevel.A bitwise combination of the AuthenticationLevel values. La valeur par défaut est MutualAuthRequested.The default value is MutualAuthRequested.

Lors d'une authentification mutuelle, le client et le serveur doivent tous les deux fournir des informations d'identification pour établir leur identité.In mutual authentication, both the client and server present credentials to establish their identity. Les valeurs MutualAuthRequired et MutualAuthRequested sont pertinentes pour l'authentification Kerberos.The MutualAuthRequired and MutualAuthRequested values are relevant for Kerberos authentication. L'authentification Kerberos peut être prise en charge directement ou être employée si le protocole Négocier la sécurité est utilisé afin de sélectionner le protocole de sécurité réel.Kerberos authentication can be supported directly, or can be used if the Negotiate security protocol is used to select the actual security protocol. Pour plus d’informations sur les protocoles d’authentification, consultez authentification Internet.For more information about authentication protocols, see Internet Authentication.

Pour déterminer si l'authentification mutuelle s'est produite, vérifiez la propriété IsMutuallyAuthenticated.To determine whether mutual authentication occurred, check the IsMutuallyAuthenticated property.

Si vous spécifiez la valeur de l'indicateur d'authentification MutualAuthRequired et que l'authentification mutuelle ne se produit pas, votre application reçoit une exception IOException avec une exception interne ProtocolViolationException qui indique que l'authentification mutuelle a échoué.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.

Exemples

L’exemple de code suivant définit la valeur de cette propriété.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();
}

S’applique à