AuthenticationLevel Wyliczenie

Definicja

Określa wymagania klienta dotyczące uwierzytelniania i personifikacji w przypadku używania WebRequest klas i klas pochodnych do żądania zasobu.

public enum class AuthenticationLevel
public enum AuthenticationLevel
type AuthenticationLevel = 
Public Enum AuthenticationLevel
Dziedziczenie
AuthenticationLevel

Pola

MutualAuthRequested 1

Klient i serwer powinny być uwierzytelniane. Żądanie nie kończy się niepowodzeniem, jeśli serwer nie jest uwierzytelniony. Aby określić, czy wystąpiło wzajemne uwierzytelnianie, sprawdź wartość IsMutuallyAuthenticated właściwości.

MutualAuthRequired 2

Klient i serwer powinny być uwierzytelniane. Jeśli serwer nie jest uwierzytelniony, aplikacja otrzyma wyjątek IOException wewnętrzny wskazujący ProtocolViolationException , że wzajemne uwierzytelnianie nie powiodło się.

None 0

Dla klienta i serwera nie jest wymagane żadne uwierzytelnianie.

Przykłady

W poniższym przykładzie kodu pokazano ustawianie flag uwierzytelniania dla żądania.

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

Uwagi

Wartości tego wyliczenia są używane do ustawiania AuthenticationLevel właściwości .

Uwaga

Wartości MutualAuthRequired i MutualAuthRequested są istotne dla uwierzytelniania Kerberos. Uwierzytelnianie Kerberos może być obsługiwane bezpośrednio lub może być używane, jeśli protokół zabezpieczeń Negotiate jest używany do wybierania rzeczywistego protokołu zabezpieczeń. Aby uzyskać więcej informacji na temat protokołów uwierzytelniania, zobacz Uwierzytelnianie internetowe.

Dotyczy