0

I have a small web application which is being currently hosted in a Virtual Machine. The machine has Windows 8 + IIS 7.

As part of the application, I need to get the user name of the people who visit this bloody web application. But every time that I tried to get the current user, I always get the Virtual Machine name.

How can I correctly get the name of the machine, who visit that app. on the Virtual Machine?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 2
    Is this ASP.NET MVC? You should only use the `model-view-controller` tag when you have a question specifically about the design pattern. Tag with `asp.net-mvc` when you have a question about the framework. – mason Apr 24 '17 at 12:18
  • I already used " GetIPHost.HostName" , "Security.Principal.WindowsIdentity.GetCurrent()" and "Environment.UserName". But did not work.. – achilles41 Apr 24 '17 at 12:23
  • `user name of the people who visit this bloody web application`. Are the users signed in with Active Directory? – Drew Kennedy Apr 24 '17 at 12:25
  • Yes Drew Kennedy. All users signed in with Active Directory.. – achilles41 Apr 24 '17 at 12:27

2 Answers2

0

On the controller, whether with Windows or Forms Auth, you should be able to get the user via:

this.User.Identity.Name

Or from the HTTP Context:

HttpContext.Current.User.Identity.Name
Brian Mains
  • 50,520
  • 35
  • 148
  • 257
0

If the user is logged in via Active Directory, this should work:

System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
Drew Kennedy
  • 4,118
  • 4
  • 24
  • 34