AuthenticationLevel 枚举

定义

指定使用 WebRequest 类和派生类请求资源时,客户端对身份验证和模拟的要求。Specifies client requirements for authentication and impersonation when using the WebRequest class and derived classes to request a resource.

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

字段

MutualAuthRequested 1

应对客户端和服务器进行身份验证。The client and server should be authenticated. 如果未对服务器进行身份验证,请求不会失败。The request does not fail if the server is not authenticated. 若要确定是否已进行相互身份验证,请检查 IsMutuallyAuthenticated 属性的值。To determine whether mutual authentication occurred, check the value of the IsMutuallyAuthenticated property.

MutualAuthRequired 2

应对客户端和服务器进行身份验证。The client and server should be authenticated. 如果服务器未进行身份验证,应用程序将收到一个 IOException,它具有一个指示相互身份验证已失败的 ProtocolViolationException 内部异常。If the server is not authenticated, your application will receive an IOException with a ProtocolViolationException inner exception that indicates that mutual authentication failed.

None 0

不要求对客户端和服务器进行身份验证。No authentication is required for the client and server.

示例

下面的代码示例演示如何设置请求的身份验证标志。The following code example demonstrates setting the authentication flags for a request.

// 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 属性。The values of this enumeration are used to set the AuthenticationLevel property.

备注

MutualAuthRequired 和 MutualAuthRequested 值与 Kerberos 身份验证有关。The MutualAuthRequired and MutualAuthRequested values are relevant for Kerberos authentication. 可以直接支持 Kerberos 身份验证,也可以仅在使用 Negotiate 安全协议选择实际的安全协议时使用该身份验证。Kerberos authentication can be supported directly, or can be used if the Negotiate security protocol is used to select the actual security protocol. 有关身份验证协议的详细信息,请参阅Internet 身份验证For more information about authentication protocols, see Internet Authentication.

适用于