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 свойства.
Если требуется HttpListener , чтобы объект использовал различные механизмы проверки подлинности на основе характеристик получаемых запросов (например, запроса Url или UserHostName свойства), необходимо реализовать метод, который выбирает схему проверки подлинности. Инструкции по этому использованию см. в документации по свойству AuthenticationSchemeSelectorDelegate .
Замечание
Чтобы задать это свойство, чтобы включить Дайджест, NTLM или Согласование, требуется SecurityPermission, ControlPrincipal.