This documentation is archived and is not being maintained.

HttpContext::User Property

Updated: May 2010

Gets or sets security information for the current HTTP request.

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

public:
property IPrincipal^ User {
	IPrincipal^ get ();
	void set (IPrincipal^ value);
}

Property Value

Type: System.Security.Principal::IPrincipal
Security information for the current HTTP request.

Setting the User property requires the ControlPrincipal flag to be set. For more 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.

TopicLocation
How to: Implement Passport Authentication in ASP.NET ApplicationsBuilding ASP .NET Web Applications

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.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Date

History

Reason

May 2010

Fixed broken ControlPrincipal link.

Customer feedback.

Show: