Skip to main content
.NET Framework Class Library
HttpContextUser Property

Gets or sets security information for the current HTTP request.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)
Syntax
Public Property User As [%$TOPIC/759we0b1_en-us_VS_110_1_0_0_0_0%]
public [%$TOPIC/759we0b1_en-us_VS_110_1_0_1_0_0%] User { get; set; }
public:
property [%$TOPIC/759we0b1_en-us_VS_110_1_0_2_0_0%]^ User {
	[%$TOPIC/759we0b1_en-us_VS_110_1_0_2_0_1%]^ get ();
	void set ([%$TOPIC/759we0b1_en-us_VS_110_1_0_2_0_2%]^ value);
}
member User : [%$TOPIC/759we0b1_en-us_VS_110_1_0_3_0_0%] with get, set

Property Value

Type: System.Security.PrincipalIPrincipal
Security information for the current HTTP request.
Remarks

Setting SkipAuthorization requires the ControlPrincipal flag to be set. For information about the ControlPrincipal flag, see SecurityPermissionFlag.

The User property provides programmatic access to the properties and methods of the IPrincipal interface. Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the HttpContext class), you can reference the members of HttpContext on an .aspx page without using the fully qualified class reference to HttpContext. For example, you can use User.Identity.Name to get the name of the user on whose behalf the current process is running. However, if you want to use the members of IPrincipal from an ASP.NET code-behind module, you must include a reference to the System.Web namespace in the module and a fully qualified reference to both the currently active request/response context and the class in System.Web that you want to use. For example, in a code-behind page you must specify the fully qualified name HttpContext.Current.User.Identity.Name.

Examples

The following example shows how to access properties about the current user through the User property. Those properties are used to set the title of the Web page.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If (User.Identity.IsAuthenticated) Then
        Page.Title = "Home page for " + User.Identity.Name
    Else
        Page.Title = "Home page for guest user." 
    End If 
End Sub
protected void Page_Load(object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated)
    {
        Page.Title = "Home page for " + User.Identity.Name;
    }
    else
    {
        Page.Title = "Home page for guest user.";
    }
}
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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