This documentation is archived and is not being maintained.

HttpListenerContext.User Property

Gets an object used to obtain identity, authentication information, and security roles for the client whose request is represented by this HttpListenerContext object.

Namespace:  System.Net
Assembly:  System (in System.dll)

Public ReadOnly Property User As IPrincipal

Property Value

Type: System.Security.Principal.IPrincipal
An IPrincipal object that describes the client, or Nothing if the HttpListener that supplied this HttpListenerContext does not require authentication.

An HttpListener indicates that it requires authentication using the AuthenticationSchemes property or by specifying an AuthenticationSchemeSelector delegate using the AuthenticationSchemeSelectorDelegate property.

To determine the client's login name and authentication information, check the IPrincipal.Identity property in the object returned by this property.

The following code example demonstrates accessing identity and authentication information about the client, and returning it to the client in the response.

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)
        display = String.Format("{0} was not authenticated", id.Name)
    End If
    Return display
End Function

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.