[RESOLVED]HttpContext.Current.User.Identity.Name always returning identity name of IIS user

I know this is same old question. I searched through Internet for it, found so many questions/blogs for it but didn’t find solution that useful in my scenario. I am creating Intranet application in ASP.Net MVC 4. I already enabled windows authentication(NTLM
provider selected on IIS), impersonation(ASP.Net Impersonation Settings -> Authenticated user selected) and disabled anonymous access on both in my VS2012 project and IIS 7.
 When user access site instead of showing username/password prompt, I want
to get windows account username of user who is currently accessing this intranet site. For hiding username/password prompt I am opening application in IE and added entry in Tools => Internet Options => Security Tab => Local Intranet => Sites => Advanced
=> added my application’s address here. Also in done entry in Tools => Internet Options => Security Tab => Local Intranet => Custom level => User Authentication => Logon => selected Automatic logon with current user name and password. Hiding prompt is works
properly in IE.
 Now for getting current user’s windows account username I am using following code:


Now this intranet application is hosted on my machine’s IIS. When I access this from my machine it shows me my MachineName/username on my IE but same is access from my colleague’s machine which is in same network instead of showing my colleague’s MachineName/username it is showing my MachineName/username. Even I try to access it from other machine too in same network it’s always showing my MachineName/username. Why this is happening? I want to get MachineName/username of user who is currently accessing intranet site. How do I achieve this?

NOTE: All computers in my network are in same workgroup. Is it creating problem?


Please check if you set the application pool identity as ApplicationPoolIdentity and enable impersonation. And try to set physical path credentials as "application user"(via r-click your mvc app->manage application in iis manager).

Leave a Reply