HttpListener.AuthenticationSchemes HttpListener.AuthenticationSchemes HttpListener.AuthenticationSchemes HttpListener.AuthenticationSchemes Property

定義

クライアントの認証に使用する方式を取得または設定します。Gets or sets the scheme used to authenticate clients.

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

プロパティ値

クライアントの認証方法を示す AuthenticationSchemes 列挙値のビットごとの組み合わせ。A bitwise combination of AuthenticationSchemes enumeration values that indicates how clients are to be authenticated. 既定値は Anonymous です。The default value is Anonymous.

例外

このオブジェクトは閉じられました。This object has been closed.

次のコード例は、 AuthenticationSchemesプロパティを使用して認証スキームを指定する方法を示しています。The following code example demonstrates using the AuthenticationSchemes property to specify an authentication scheme.

public static void SimpleListenerWithUnsafeAuthentication(string[] prefixes)
{
    // URI prefixes are required,
    // for example "http://contoso.com:8080/index/".
    if (prefixes == null || prefixes.Length == 0)
      throw new ArgumentException("prefixes");
    // Set up a listener.
    HttpListener listener = new HttpListener();
    foreach (string s in prefixes)
    {
        listener.Prefixes.Add(s);
    }
    listener.Start();
    // Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate;
    // If NTLM is used, we will allow multiple requests on the same
    // connection to use the authentication information of first request.
    // This improves performance but does reduce the security of your 
    // application. 
    listener.UnsafeConnectionNtlmAuthentication = true;
    // This listener does not want to receive exceptions 
    // that occur when sending the response to the client.
    listener.IgnoreWriteExceptions = true;
    Console.WriteLine("Listening...");
    // ... process requests here.

    listener.Close();
}
Public Shared Sub SimpleListenerWithUnsafeAuthentication(ByVal prefixes As String())
    ' URI prefixes are required,
    ' for example "http://contoso.com:8080/index/".
    If prefixes Is Nothing OrElse prefixes.Length = 0 Then Throw New ArgumentException("prefixes")
    ' Set up a listener.
    Dim listener As HttpListener = New HttpListener()

    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next

    listener.Start()
    ' Specify Negotiate as the authentication scheme.
    listener.AuthenticationSchemes = AuthenticationSchemes.Negotiate
    ' If NTLM Is used, we will allow multiple requests on the same
    ' connection to use the authentication information of first request.
    ' This improves performance but does reduce the security of your 
    ' application. 
    listener.UnsafeConnectionNtlmAuthentication = True
    ' This listener does Not want to receive exceptions 
    ' that occur when sending the response to the client.
    listener.IgnoreWriteExceptions = True
    Console.WriteLine("Listening...")
    ' ... process requests here.

    listener.Close()
End Sub

注釈

HttpListener 、指定されたスキームを使用してすべての受信要求を認証します。The HttpListener uses the specified scheme to authenticate all incoming requests. メソッドGetContextEndGetContextメソッドは、がHttpListener要求を正常に認証した場合にのみ、受信クライアント要求を返します。The GetContext and EndGetContext methods return an incoming client request only if the HttpListener successfully authenticates the request.

HttpListenerContext.Userプロパティを使用して、正常に認証されたクライアントの id を照会できます。You can interrogate the identity of a successfully authenticated client by using the HttpListenerContext.User property.

オブジェクトが受信する要求の特性 (要求のUrlプロパティやUserHostNameプロパティなど) に基づいて異なる認証メカニズムを使用する場合は、次を選択するメソッドを実装する必要があります。 HttpListener認証スキーム。If you want an HttpListener object to use different authentication mechanisms based on characteristics of the requests it receives (for example, the request's Url or UserHostName property), you must implement a method that chooses the authentication scheme. この方法の手順については、プロパティAuthenticationSchemeSelectorDelegateのドキュメントを参照してください。For instructions about how to do this, see the AuthenticationSchemeSelectorDelegate property documentation.

注意

このプロパティを [ダイジェスト、NTLM、またはネゴシエートを有効にSecurityPermissionするControlPrincipal] に設定するには、、、のいずれかが必要です。To set this property to enable Digest, NTLM, or Negotiate requires the SecurityPermission, ControlPrincipal.

適用対象