AuthenticationSchemes 列舉
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定驗證的通訊協定。
此列舉支援其成員值的位元組合。
public enum class AuthenticationSchemes
C#
[System.Flags]
public enum AuthenticationSchemes
[<System.Flags>]
type AuthenticationSchemes =
Public Enum AuthenticationSchemes
- 繼承
- 屬性
名稱 | 值 | Description |
---|---|---|
Anonymous | 32768 | 指定匿名驗證。 |
Basic | 8 | 指定基本驗證。 |
Digest | 1 | 指定摘要式驗證。 |
IntegratedWindowsAuthentication | 6 | 指定 Windows 驗證。 |
Negotiate | 2 | 與用戶端交涉,以決定驗證配置。 如果用戶端和伺服器都支援 Kerberos,就使用它,否則使用 NTLM。 |
None | 0 | 不允許驗證。 用戶端要求的 HttpListener 物件已設定這個旗標時,一定會收到 403 禁止狀態。 當資源絕對不可提供給用戶端時,請使用這個旗標。 |
Ntlm | 4 | 指定 NTLM 驗證。 |
下列程式代碼範例示範如何使用 Negotiate 列舉值來指定用戶端是使用 Negotiate 安全性通訊協定進行驗證。
C#
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。
產品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |