AuthenticationLevel 枚举

定义

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

C#
public enum AuthenticationLevel
继承
AuthenticationLevel

字段

名称 说明
MutualAuthRequested 1

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

MutualAuthRequired 2

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

None 0

不要求对客户端和服务器进行身份验证。

示例

下面的代码示例演示如何设置请求的身份验证标志。

C#

// 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 身份验证

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0