0

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?

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • I don't understand. Why do you need another way to get it? – freefaller Sep 13 '12 at 16:45
  • I was just doing a search to find the other way out. Although this is working for me. I was just enquiring if I can find some other way too... – Rahul Tripathi Sep 13 '12 at 16:47
  • 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[0] will have the Domain and strRawUser[1] will have the users login id – MethodMan Sep 13 '12 at 16:57

2 Answers2

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 "DomainName\UserName" 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]
MethodMan
  • 18,625
  • 6
  • 34
  • 52
0

You can also get the current user identity using Principal Object.

Praveen
  • 100
  • 8