|
Principal Object |
Identity Object |
Purpose: |
Represent the current security context of user. It combines user's identity with other information like Role, Priviledge etc and therefore allow to perform Roles based Authorization. |
Represent successfully authenticated user and therefore provides user information such as user name. |
Interface: |
IPrincipal Interface |
IIdentity Interface |
|
provides information about the current user |
The IIdentity interface defines the basic information needed to represent the current user |
Property: |
1. Identity: provides information about the current user |
1. AuthenticationType: returns the type of authentication used as string, i.e. form, window |
Methods: |
1. IsInRole(): to test whether current user is member of a role say admin. |
2.IsAuthenticated: Returns a boolean value which tell whether user has been authenticated or(true) is anonymous(false)
3.Name: return the name of current user as string
Example: if (HttpContext.Current.User.Identity.IsAuthenticated) { lblUserName.Text = HttpContext.Current.User.Identity.Name + " is logged in"; } |
|
Example: if (HttpContext.Current.User.IsInRole("Admin")) |
|