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,就使用它,否則使用 NTLM。

None 0

不允許驗證。 用戶端要求的 HttpListener 物件已設定這個旗標時,一定會收到 403 禁止狀態。 當資源絕對不可提供給用戶端時,請使用這個旗標。

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

適用於