HttpListenerContext.User Propriedade

Definição

Obtém um objeto usado para obter identidade, informações de autenticação e funções de segurança para o cliente cujo pedido é representado por este HttpListenerContext objeto.

public:
 property System::Security::Principal::IPrincipal ^ User { System::Security::Principal::IPrincipal ^ get(); };
public System.Security.Principal.IPrincipal User { get; }
member this.User : System.Security.Principal.IPrincipal
Public ReadOnly Property User As IPrincipal

Valor de Propriedade

Um objeto que descreve o cliente, ou null se o HttpListener fornecido, IPrincipalHttpListenerContext não requer autenticação.

Exemplos

O exemplo de código seguinte demonstra como aceder à informação de identidade e autenticação do cliente, e devolvê-la ao cliente na resposta.

public static string ClientInformation(HttpListenerContext context)
{
    System.Security.Principal.IPrincipal user = context.User;
    System.Security.Principal.IIdentity id = user.Identity;
    if (id == null)
    {
        return "Client authentication is not enabled for this Web server.";
    }

    string display;
    if (id.IsAuthenticated)
    {
        display = String.Format("{0} was authenticated using {1}", id.Name,
            id.AuthenticationType);
    }
    else
    {
       display = String.Format("{0} was not authenticated", id.Name);
    }
    return display;
}
Public Shared Function ClientInformation(ByVal context As HttpListenerContext) As String
    Dim user As System.Security.Principal.IPrincipal = context.User
    Dim id As System.Security.Principal.IIdentity = user.Identity

    If id Is Nothing Then
        Return "Client authentication is not enabled for this Web server."
    End If

    Dim display As String

    If id.IsAuthenticated Then
        display = String.Format("{0} was authenticated using {1}", id.Name, id.AuthenticationType)
    Else
        display = String.Format("{0} was not authenticated", id.Name)
    End If

    Return display
End Function

Observações

An indica que requer autenticação HttpListener usando a AuthenticationSchemes propriedade ou especificando um AuthenticationSchemeSelector delegado usando a AuthenticationSchemeSelectorDelegate propriedade.

Para determinar o nome de login e a informação de autenticação do cliente, verifique a IPrincipal.Identity propriedade no objeto devolvida por esta propriedade.

Aplica-se a