Share via


WebRequest.AuthenticationLevel Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan tingkat autentikasi dan peniruan yang digunakan untuk permintaan ini.

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

Nilai Properti

Kombinasi bitwise dari AuthenticationLevel nilai. Nilai defaultnya adalah MutualAuthRequested.

Dalam autentikasi bersama, klien dan server menyajikan kredensial untuk menetapkan identitas mereka. Nilai MutualAuthRequired dan MutualAuthRequested relevan untuk autentikasi Kerberos. Autentikasi Kerberos dapat didukung secara langsung, atau dapat digunakan jika protokol keamanan Negosiasi digunakan untuk memilih protokol keamanan aktual. Untuk informasi selengkapnya tentang protokol autentikasi, lihat Autentikasi Internet.

Untuk menentukan apakah terjadi autentikasi timbal balik, periksa IsMutuallyAuthenticated properti .

Jika Anda menentukan MutualAuthRequired nilai bendera autentikasi dan autentikasi timbal balik tidak terjadi, aplikasi Anda akan menerima IOException dengan ProtocolViolationException pengecualian dalam yang menunjukkan bahwa autentikasi timbal balik gagal.

Contoh

Contoh kode berikut menetapkan nilai properti ini.

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

Berlaku untuk