AuthenticationSchemeSelector 代理人
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
選取 HttpListener 執行個體的驗證配置。
public delegate System::Net::AuthenticationSchemes AuthenticationSchemeSelector(HttpListenerRequest ^ httpRequest);
C#
public delegate System.Net.AuthenticationSchemes AuthenticationSchemeSelector(HttpListenerRequest httpRequest);
type AuthenticationSchemeSelector = delegate of HttpListenerRequest -> AuthenticationSchemes
Public Delegate Function AuthenticationSchemeSelector(httpRequest As HttpListenerRequest) As AuthenticationSchemes
- httpRequest
- HttpListenerRequest
要選取驗證配置的 HttpListenerRequest 執行個體。
其中一個 AuthenticationSchemes 值,指出要用於指定用戶端要求的驗證方法。
下列範例會使用這個類型的實例來設定 AuthenticationSchemeSelectorDelegate 屬性。
C#
// Set up a listener.
HttpListener listener = new HttpListener();
HttpListenerPrefixCollection prefixes = listener.Prefixes;
prefixes.Add(@"http://localhost:8080/");
prefixes.Add(@"http://contoso.com:8080/");
// Specify the authentication delegate.
listener.AuthenticationSchemeSelectorDelegate =
new AuthenticationSchemeSelector (AuthenticationSchemeForClient);
// Start listening for requests and process them
// synchronously.
listener.Start();
' Set up a listener.
Dim listener As New HttpListener()
Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes
prefixes.Add("http://localhost:8080/")
prefixes.Add("http://contoso.com:8080/")
' Specify the authentication delegate.
listener.AuthenticationSchemeSelectorDelegate = New AuthenticationSchemeSelector(AddressOf AuthenticationSchemeForClient)
' Start listening for requests and process them
' synchronously.
listener.Start()
下列範例顯示上一個範例中委派叫用 AuthenticationSchemeSelector 的方法實作。
C#
static AuthenticationSchemes AuthenticationSchemeForClient(HttpListenerRequest request)
{
Console.WriteLine("Client authentication protocol selection in progress...");
// Do not authenticate local machine requests.
if (request.RemoteEndPoint.Address.Equals (IPAddress.Loopback))
{
return AuthenticationSchemes.None;
}
else
{
return AuthenticationSchemes.IntegratedWindowsAuthentication;
}
}
Private Shared Function AuthenticationSchemeForClient(ByVal request As HttpListenerRequest) As AuthenticationSchemes
Console.WriteLine("Client authentication protocol selection in progress...")
' Do not authenticate local machine requests.
If request.RemoteEndPoint.Address.Equals(IPAddress.Loopback) Then
Return AuthenticationSchemes.None
Else
Return AuthenticationSchemes.IntegratedWindowsAuthentication
End If
End Function
實例會使用此 HttpListener 類型的委派,根據要求的特性來選取驗證配置。
AuthenticationSchemeSelector委派會針對未提供驗證資訊的每個傳入要求傳遞HttpListenerRequest物件。 委派叫用的方法會 HttpListenerRequest 使用 物件和任何其他可用信息來決定需要哪一個驗證配置。 委派是使用 AuthenticationSchemeSelectorDelegate 屬性來指定。
Get |
取得表示特定委派所代表之方法的物件。 |
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.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 | 2.0, 2.1 |