Share via


HttpListener.AuthenticationSchemeSelectorDelegate Özellik

Tanım

İstemcilerin kimliğini doğrulamak için kullanılan protokolü belirlemek için çağrılan temsilciyi alır veya ayarlar.

public:
 property System::Net::AuthenticationSchemeSelector ^ AuthenticationSchemeSelectorDelegate { System::Net::AuthenticationSchemeSelector ^ get(); void set(System::Net::AuthenticationSchemeSelector ^ value); };
public System.Net.AuthenticationSchemeSelector? AuthenticationSchemeSelectorDelegate { get; set; }
public System.Net.AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate { get; set; }
member this.AuthenticationSchemeSelectorDelegate : System.Net.AuthenticationSchemeSelector with get, set
Public Property AuthenticationSchemeSelectorDelegate As AuthenticationSchemeSelector

Özellik Değeri

Bir AuthenticationSchemeSelector kimlik doğrulama protokolü seçmek için kullanılan yöntemi çağıran bir temsilci. null varsayılan değerdir.

Özel durumlar

Bu nesne kapatıldı.

Örnekler

Aşağıdaki kod örneği bu özelliğin değerini ayarlar.

// 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()

Aşağıdaki kod örneği, bir temsilci tarafından AuthenticationSchemeSelector çağrılan bir yöntemin uygulamasını sağlar.

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

Açıklamalar

Not

Belirli bir örneği tarafından işlenen tüm istekler için aynı kimlik doğrulama protokolünün HttpListenerkullanılmasını istiyorsanız, bu özelliği ayarlamanız gerekmez. Tüm istemci isteklerinde kullanılacak protokolü belirtmek için özelliğini kullanın AuthenticationSchemes .

İstemci üst bilgilerinde kimlik doğrulama bilgileri belirtmediyse, istemcinin HttpListener kimliğini doğrulamak için kullanılacak protokolü belirlemek üzere kimliği doğrulanmamış her gelen istek için belirtilen temsilciyi çağırır. GetContext ve EndGetContext yöntemleri yalnızca isteğin HttpListener kimliğini başarıyla doğrularsa gelen isteği döndürür. bir isteğin kimliği doğrulanamazsa, HttpListener otomatik olarak bir 401 yanıtı geri gönderir. özelliğini kullanarak başarıyla kimliği doğrulanmış bir istemcinin HttpRequest.LogonUserIdentity kimliğini alabilirsiniz.

Kimlik doğrulama protokolü seçimini uygulamaya özgü bir yönteme devretme özelliği, bir örneğinin HttpListener aldığı isteklerin özelliklerine (örneğin, isteğin Url veya UserHostAddress özelliğinin) bağlı olarak farklı kimlik doğrulama protokolleri kullanmasını istiyorsanız kullanışlıdır.

Not

Bu özelliği Özet, NTLM veya Anlaşma'yı etkinleştirecek şekilde ayarlamak için , ControlPrincipalgerekirSecurityPermission.

Şunlara uygulanır