AuthenticationLevel 枚举

定义

指定使用 WebRequest 类和派生类请求资源时,客户端对身份验证和模拟的要求。

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

字段

MutualAuthRequested 1

应对客户端和服务器进行身份验证。 如果未对服务器进行身份验证,请求不会失败。 若要确定是否已进行相互身份验证,请检查 IsMutuallyAuthenticated 属性的值。

MutualAuthRequired 2

应对客户端和服务器进行身份验证。 如果服务器未进行身份验证,应用程序将收到一个 IOException,它具有一个指示相互身份验证已失败的 ProtocolViolationException 内部异常。

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 身份验证,也可以仅在使用 Negotiate 安全协议选择实际的安全协议时使用该身份验证。 有关身份验证协议的详细信息,请参阅 Internet 身份验证

适用于