HttpListener.AuthenticationSchemes プロパティ

定義

クライアントの認証に使用する方式を取得または設定します。

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 列挙値のビットごとの組み合わせ。 既定値は Anonymous です。

例外

このオブジェクトは閉じられました。

次のコード例では、 プロパティを AuthenticationSchemes 使用して認証スキームを指定する方法を示します。

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 、指定したスキームを使用して、すべての受信要求を認証します。 メソッドと EndGetContext メソッドはGetContext、 が要求を正常に認証した場合HttpListenerにのみ、受信クライアント要求を返します。

プロパティを使用して HttpListenerContext.User 、正常に認証されたクライアントの ID を尋問できます。

オブジェクトが受信したHttpListener要求の特性 (たとえば、要求の または UserHostName プロパティ) に基づいて異なる認証メカニズムを使用する場合はUrl、認証スキームを選択するメソッドを実装する必要があります。 この方法の手順については、プロパティのドキュメントを AuthenticationSchemeSelectorDelegate 参照してください。

注意

ダイジェスト、NTLM、またはネゴシエートを有効にするようにこのプロパティを設定するには、 SecurityPermissionControlPrincipal必要です。

適用対象