Export (0) Print
Expand All

Page.User Property

Gets information about the user making the page request.

[Visual Basic]
Public ReadOnly Property User As IPrincipal
[C#]
public IPrincipal User {get;}
[C++]
public: __property IPrincipal* get_User();
[JScript]
public function get User() : IPrincipal;

Property Value

An IPrincipal object that represents the user making the page request.

Remarks

An IPrincipal object represents the security context of the user on whose behalf the code is running, including that user's identity and any roles to which they belong.

This property uses the HttpContext object's User property to determine where the request originates.

Example

[Visual Basic] The following example uses the Page.User property to access authentication and identity information for the current user. If the user is not authenticated, it redirects them to a login page.

[Visual Basic] 
' Use the Page.User property to access authentication and
' identity information for the current user. If the user is
' not authenticated, redirect them to a login page.
Sub Page_Load(sender As Object , e As EventArgs)
   If User.Identity.IsAuthenticated Then
      msgLabel1.Text = "Welcome, <B>" + User.Identity.Name + "</B>!"
   Else
      Response.Redirect("LoginVB.aspx")
   End If
End Sub

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Page Class | Page Members | System.Web.UI Namespace | HttpContext | IPrincipal

Show:
© 2014 Microsoft