WebRequest.AuthenticationLevel Propiedad

Definición

Obtiene o establece valores que indican el nivel de autenticación y suplantación que se usa para esta solicitud.

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

Valor de propiedad

Combinación bit a bit de los AuthenticationLevel valores. El valor por defecto es MutualAuthRequested.

En la autenticación mutua, tanto el cliente como el servidor presentan credenciales para establecer su identidad. Los MutualAuthRequired valores y MutualAuthRequested son pertinentes para la autenticación Kerberos. La autenticación Kerberos se puede admitir directamente o se puede usar si se usa el protocolo de seguridad Negotiate para seleccionar el protocolo de seguridad real. Para obtener más información sobre los protocolos de autenticación, consulte Autenticación de Internet.

Para determinar si se ha producido la autenticación mutua, compruebe la IsMutuallyAuthenticated propiedad .

Si especifica el valor de la MutualAuthRequired marca de autenticación y la autenticación mutua no se produce, la aplicación recibirá una IOException excepción interna que indica que se produjo un ProtocolViolationException error de autenticación mutua.

Ejemplos

En el ejemplo de código siguiente se establece el valor de esta propiedad.


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

Se aplica a