HttpListenerContext.User Свойство

Определение

Возвращает объект, используемый для получения идентификации, сведений проверки подлинности и ролей безопасности для клиента, запрос которого представлен этим объектом HttpListenerContext.

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

Значение свойства

Объект IPrincipal, который описывает клиента, или значение null, если объект HttpListener, предоставивший этот объект HttpListenerContext, не требует проверки подлинности.

Примеры

В следующем примере кода показано, как получить доступ к сведениям об удостоверении и проверке подлинности клиента и вернуть их клиенту в ответе.

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

Комментарии

Указывает HttpListener , что требуется проверка подлинности с помощью AuthenticationSchemes свойства или указание делегата AuthenticationSchemeSelectorAuthenticationSchemeSelectorDelegate с помощью свойства .

Чтобы определить имя для входа клиента и сведения о проверке подлинности, проверка IPrincipal.Identity свойство в объекте , возвращаемом этим свойством.

Применяется к