AuthenticationSchemes 枚举

定义

指定身份验证的协议。

此枚举支持其成员值的按位组合。

C#
[System.Flags]
public enum AuthenticationSchemes
继承
AuthenticationSchemes
属性

字段

名称 说明
Anonymous 32768

指定匿名身份验证。

Basic 8

指定基本身份验证。

Digest 1

指定摘要式身份验证。

IntegratedWindowsAuthentication 6

指定 Windows 身份验证。

Negotiate 2

和客户端协商以确定身份验证方案。 如果客户端和服务器均支持 Kerberos,则使用 Kerberos;否则使用 NTLM。

None 0

不允许进行任何身份验证。 设置了此标志并请求 HttpListener 对象的客户端将始终会接收 403 Forbidden 状态。 当资源决不应该用于客户端时,请使用此标志。

Ntlm 4

指定 NTLM 身份验证。

示例

下面的代码示例演示如何使用 Negotiate 枚举值来指定使用 Negotiate 安全协议对客户端进行身份验证。

C#
Console.WriteLine("Listening for {0} prefixes...", listener.Prefixes.Count);
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
Console.WriteLine("Received a request.");
// This server requires a valid client certificate
// for requests that are not sent from the local computer.

// Did the client omit the certificate or send an invalid certificate?
if (request.IsAuthenticated &&
    request.GetClientCertificate() == null ||
    request.ClientCertificateError != 0)
{
    // Send a 403 response.
    HttpListenerResponse badCertificateResponse = context.Response ;
    SendBadCertificateResponse(badCertificateResponse);
    Console.WriteLine("Client has invalid certificate.");
    continue;
}

注解

此枚举用于指定用于对对象正在处理的 HttpListener 客户端请求进行身份验证的方法。

重要

基本身份验证需要交换密码,因此应避免使用安全加密连接的情况除外。

有关基本身份验证和摘要式身份验证的其他信息,请参阅 RFC2617 - HTTP 身份验证:基本和摘要式身份验证。 本文档在 上提供 https://www.rfc-editor.org

适用于

产品 版本
.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.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0