Reputation: 111
I have a intranet website that I have developed that I want to use windows Authentication.
In my code I use the following to get the username from the logged on user to display at the top of the page.
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
ThisLoginName.Text = userName.ToString();
However what does display at the top of the username "IIS APPPOOL\WebsiteName" I have changed the IIS 7.0 Authentication to Windows Auth only.
What am I doing wrong?
Thanks
Upvotes: 1
Views: 319
Reputation: 4021
You should use: HttpContext.Current.User.Identity.Name
to get the name of the authenticated user. Your code returns the user name for the user that runs your web process on the server.
Upvotes: 2