HttpListener.AuthenticationSchemes Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define o esquema usado para autenticar clientes.
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
Valor de Propriedade
Uma combinação bit a bit de AuthenticationSchemes valores de enumeração que indica como os clientes devem ser autenticados. O valor predefinido é Anonymous.
Exceções
Este objeto foi encerrado.
Exemplos
O exemplo de código seguinte demonstra a utilização da AuthenticationSchemes propriedade para especificar um esquema de autenticação.
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
Observações
Utiliza HttpListener o esquema especificado para autenticar todos os pedidos recebidos. Os GetContext métodos e EndGetContext retornam um pedido de cliente recebido apenas se autenticar HttpListener com sucesso o pedido.
Pode interrogar a identidade de um cliente autenticado com sucesso utilizando a HttpListenerContext.User propriedade.
Se quiser que um HttpListener objeto utilize mecanismos de autenticação diferentes com base nas características dos pedidos que recebe (por exemplo, o pedido Url ou UserHostName propriedade), deve implementar um método que escolha o esquema de autenticação. Para instruções sobre como fazer isto, consulte a AuthenticationSchemeSelectorDelegate documentação da propriedade.
Note
Para definir esta propriedade para permitir Digest, NTLM ou Negotiate, é necessário o SecurityPermission, ControlPrincipal.