Once a user is authenticated and authorized, the application can get information about the user by using the User object’s Identity property. The Identity property returns an object that includes the user name and role information.
Below is the code snippet which I have used to understand the concept:-
private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = User.Identity.IsAuthenticated.ToString();
Label2.Text = User.Identity.Name;
Label3.Text = User.Identity.AuthenticationType;
}
Is there any other way to get the User Identity?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Please clarify if you are wanting something like the following below..
If you just want the users Identity.. from an ASP.NET WebPage when the Page_Load is called create a string[] and do something like the following
string strRawUser = Page.User.Identity.Name;
Then from there strRawUser will have something like “DomainNameUserName”
So you need to Split the string into an stringArray and get the string[1] value like this
string[] strRawUserSplitter = Page.User.Identity.Name.Split("\");
Label2.Text = strRawUserSplitter[1]
Method 2
You can also get the current user identity using Principal Object.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0