AuthenticationSchemes 枚举

定义

指定身份验证的协议。

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

public enum class AuthenticationSchemes
[System.Flags]
public enum AuthenticationSchemes
[<System.Flags>]
type AuthenticationSchemes = 
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 安全协议对客户端进行身份验证。

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 客户端请求进行身份验证的方法。

重要

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

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

适用于