WebRequest.AuthenticationLevel Proprietà

Definizione

Ottiene o imposta i valori che indicano il livello di autenticazione e di rappresentazione usati per la richiesta.

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

Valore della proprietà

AuthenticationLevel

Combinazione bit per bit dei valori di AuthenticationLevel. Il valore predefinito è MutualAuthRequested.

Nell'autenticazione reciproca il client e il server presentano entrambi credenziali per definire la propria identità. I valori MutualAuthRequired e MutualAuthRequested sono rilevanti per l'autenticazione Kerberos. L'autenticazione Kerberos può essere supportata direttamente oppure può essere usata se per selezionare il protocollo di sicurezza effettivo viene impiegato il protocollo di sicurezza Negotiate. Per altre informazioni sui protocolli di autenticazione, vedere Autenticazione Internet.

Per determinare se è stata effettuata l'autenticazione reciproca, verificare la proprietà IsMutuallyAuthenticated.

Se si specifica il valore del flag di autenticazione MutualAuthRequired e non si verifica l'autenticazione reciproca, l'applicazione riceverà un'eccezione IOException con un'eccezione interna ProtocolViolationException che indica che l'autenticazione reciproca non è riuscita.

Esempio

Nell'esempio di codice seguente viene impostato il valore di questa proprietà.

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

Si applica a