AuthenticationSchemes Enum


指定身份验证的协议。Specifies protocols for authentication.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

public enum class AuthenticationSchemes
public enum AuthenticationSchemes
type AuthenticationSchemes = 
Public Enum AuthenticationSchemes


Anonymous 32768

指定匿名身份验证。Specifies anonymous authentication.

Basic 8

指定基本身份验证。Specifies basic authentication.

Digest 1

指定摘要式身份验证。Specifies digest authentication.

IntegratedWindowsAuthentication 6

指定 Windows 身份验证。Specifies Windows authentication.

Negotiate 2

和客户端协商以确定身份验证方案。Negotiates with the client to determine the authentication scheme. 如果客户端和服务器均支持 Kerberos,则使用 Kerberos;否则使用 NTLM。If both client and server support Kerberos, it is used; otherwise, NTLM is used.

None 0

不允许进行任何身份验证。No authentication is allowed. 设置了此标志并请求 HttpListener 对象的客户端将始终会接收 403 Forbidden 状态。A client requesting an HttpListener object with this flag set will always receive a 403 Forbidden status. 当资源决不应该用于客户端时,请使用此标志。Use this flag when a resource should never be served to a client.

Ntlm 4

指定 NTLM 身份验证。Specifies NTLM authentication.


下面的代码示例演示如何使用 Negotiate 枚举值指定使用协商安全协议对客户端进行身份验证。The following code example demonstrates using the Negotiate enumeration value to specify that clients are authenticated using the Negotiate security protocol.

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 ;
    Console.WriteLine("Client has invalid certificate.");
Console.WriteLine("Listening for {0} prefixes...", listener.Prefixes.Count)
Dim context As HttpListenerContext = listener.GetContext()
Dim request As HttpListenerRequest = 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 AndAlso request.GetClientCertificate() Is Nothing OrElse request.ClientCertificateError <> 0 Then
    ' Send a 403 response.
    Dim badCertificateResponse As HttpListenerResponse = context.Response
    Console.WriteLine("Client has invalid certificate.")
    Continue Do
End If


此枚举用于指定用于对 HttpListener 对象处理的客户端请求进行身份验证的方法。This enumeration is used to specify the method used to authenticate client requests being processed by HttpListener objects.


基本身份验证需要交换密码,因此应避免使用,但在安全的加密连接情况下除外。Basic authentication requires the exchange of a password and should therefore be avoided except in the case of secure, encrypted connections.

有关基本和摘要式身份验证的其他信息,请参阅RFC2617-HTTP authentication:基本和摘要式身份验证For additional information on basic and digest authentication, see RFC2617 - HTTP Authentication: Basic and Digest Authentication. 此文档在 https://www.rfc-editor.org提供。This document is available at

Applies to