共用方式為


AuthenticationLevel 列舉

定義

當使用 WebRequest 類別和衍生類別以要求資源時,指定用戶端的驗證和模擬需求。

public enum class AuthenticationLevel
public enum AuthenticationLevel
type AuthenticationLevel = 
Public Enum AuthenticationLevel
繼承
AuthenticationLevel

欄位

MutualAuthRequested 1

用戶端和伺服器都應該驗證。 如果伺服器未加以驗證,要求也不會失敗。 若要判斷是否發生相互驗證,請檢查 IsMutuallyAuthenticated 屬性的值。

MutualAuthRequired 2

用戶端和伺服器都應該驗證。 如果伺服器未經驗證,您的應用程式就會收到具有 ProtocolViolationException 內部例外狀況 (指出相互驗證失敗) 的 IOException

None 0

用戶端和伺服器都不需要驗證。

範例

下列程式代碼範例示範如何設定要求的驗證旗標。

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

備註

這個列舉的值是用來設定 AuthenticationLevel 屬性。

注意

MutualAuthRequired 和 MutualAuthRequested 值與 Kerberos 驗證相關。 Kerberos 驗證可以直接支援,或在使用交涉安全性通訊協定時,用來選取實際的安全性通訊協定。 如需驗證通訊協議的詳細資訊,請參閱 因特網驗證

適用於