AuthenticationSchemes AuthenticationSchemes AuthenticationSchemes AuthenticationSchemes Enum

定义

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

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class AuthenticationSchemes
[System.Flags]
public enum AuthenticationSchemes
type AuthenticationSchemes = 
Public Enum AuthenticationSchemes
继承
AuthenticationSchemesAuthenticationSchemesAuthenticationSchemesAuthenticationSchemes
属性

字段

Anonymous Anonymous Anonymous Anonymous 32768

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

Basic Basic Basic Basic 8

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

Digest Digest Digest Digest 1

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

IntegratedWindowsAuthentication IntegratedWindowsAuthentication IntegratedWindowsAuthentication IntegratedWindowsAuthentication 6

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

Negotiate Negotiate Negotiate 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 None None 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 Ntlm Ntlm 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 ;
    SendBadCertificateResponse(badCertificateResponse);
    Console.WriteLine("Client has invalid certificate.");
    continue;
}
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
    SendBadCertificateResponse(badCertificateResponse)
    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 https://www.rfc-editor.org.

适用于