Name
User
Synopsis
IPrincipal = Page.User
Returns an
instance of an object implementing the
IPrincipal
interface containing security information about the user making the
page request. The IPrincipal
interface implements
the following members:
Member |
Description |
---|---|
Identity property |
Returns the IIdentity object representing the user requesting the page |
IsInRole property |
Indicates whether the user requesting the page is in a particular role |
Parameters
-
IPrincipal
An object variable that implements
IPrincipal
.
Example
The example obtains the user’s authentication status and name using the User property and displays it in the browser:
Sub Page_Load( ) Message.Text = "Authenticated: " & _ User.Identity.IsAuthenticated & "<br/>" Message.Text &= "User Name: " & User.Identity.Name End Sub
Notes
In order for the IPrincipal object returned by the User property to
be populated, some form of authentication must be configured in
either machine.config
or
web.config
, and at a minimum, an authorization
rule must be configured that excludes anonymous users. If these
conditions are not met, the IsAuthenticated property of the IIdentity
object will return False
and the Name property
will return an empty string.
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.