AuthenticationSchemes 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定驗證的通訊協定。
此列舉支援其成員值的位元組合。
public enum class AuthenticationSchemes
[System.Flags]
public enum AuthenticationSchemes
[<System.Flags>]
type AuthenticationSchemes =
Public Enum AuthenticationSchemes
- 繼承
- 屬性
欄位
| 名稱 | 值 | Description |
|---|---|---|
| None | 0 | 不允許任何認證。 請求 HttpListener 帶有此標誌物件的客戶端,將永遠獲得 403 禁止狀態。 當資源絕不應該提供給客戶時,請使用此標記。 |
| Digest | 1 | 指定摘要式驗證。 |
| Negotiate | 2 | 與客戶協商以決定認證方案。 若用戶端與伺服器皆支援 Kerberos,則會使用;否則,則使用 NTLM。 |
| Ntlm | 4 | 規定NTLM認證。 |
| IntegratedWindowsAuthentication | 6 | 指定 Windows 驗證。 |
| Basic | 8 | 指定基本身份驗證。 |
| Anonymous | 32768 | 規定匿名認證。 |
範例
以下程式碼範例示範使用 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 客戶端請求的方法。
Important
基本認證需交換密碼,因此應避免使用,除非是安全且加密的連線。
欲了解更多基本與摘要認證的資訊,請參見 RFC2617 - HTTP 認證:基本與摘要認證。 此文件可於 https://www.rfc-editor.org.取得。