How can I get UserName or UserId from loginName control?

Mostafa picture Mostafa · Nov 14, 2010 · Viewed 11.3k times · Source

I'm wondering is there any way i could get UserName or UserId for current User from LoginName control in ASP.NET ?

Answer

Frédéric Hamidi picture Frédéric Hamidi · Nov 14, 2010

You could use the User property of the Page class:

string userName = Page.User.Identity.Name;