WebRequest.AuthenticationLevel Özellik

Tanım

Bu istek için kullanılan kimlik doğrulama ve kimliğe bürünme düzeyini gösteren değerleri alır veya ayarlar.

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

Özellik Değeri

AuthenticationLevel

Değerlerin bit düzeyinde birleşimi AuthenticationLevel . MutualAuthRequested varsayılan değerdir.

Karşılıklı kimlik doğrulamasında, hem istemci hem de sunucu kimliklerini oluşturmak için kimlik bilgilerini sunar. MutualAuthRequired ve MutualAuthRequested değerleri Kerberos kimlik doğrulaması için geçerlidir. Kerberos kimlik doğrulaması doğrudan desteklenebilir veya gerçek güvenlik protokollerini seçmek için Anlaşma güvenlik protokolü kullanılıyorsa kullanılabilir. Kimlik doğrulama protokolleri hakkında daha fazla bilgi için bkz. İnternet Kimlik Doğrulaması.

Karşılıklı kimlik doğrulamasının gerçekleşip gerçekleşmediğini belirlemek için özelliğini denetleyin IsMutuallyAuthenticated .

Kimlik doğrulama bayrağı değerini belirtirseniz MutualAuthRequired ve karşılıklı kimlik doğrulaması gerçekleşmezse, uygulamanız karşılıklı kimlik doğrulamasının başarısız olduğunu belirten iç özel durum içeren bir IOException ProtocolViolationException alır.

Örnekler

Aşağıdaki kod örneği bu özelliğin değerini ayarlar.

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

Şunlara uygulanır