0

I am using this line of code to get the username that the computer is logged into

 String windosUser = System.Web.HttpContext.Current.User.Identity.Name;

but the result that I am getting is that the string is empty string.

I would like to see the name of the person that is logged on the computer not the actual name of the computer

user1776590
  • 135
  • 5
  • 14
  • possible duplicate of [Get the computer user name in a web application](http://stackoverflow.com/questions/7245270/get-the-computer-user-name-in-a-web-application). – Steve B Nov 12 '12 at 14:47
  • 1
    This only works if the website is being accessed on a local intranet using Windows NTLM authentication. – Joel Etherton Nov 12 '12 at 14:47
  • possible duplicate of [get user name asp.net windows auth](http://stackoverflow.com/questions/7615458/get-user-name-asp-net-windows-auth) – Alex Nov 12 '12 at 14:47
  • Does this help: [HttpContext.Current.User.Identity.Name is Empty](http://stackoverflow.com/questions/1571036/httpcontext-current-user-identity-name-is-empty) ? – Tim Schmelter Nov 12 '12 at 14:48
  • You need to give more context. Is this an intranet site? Is this a public website? What's the purpose? Why can't you ask the user? What authentication model are you using? Have you considered the security implications of if the operating system let any visited webpage know what username you logged in with? – J. Steen Nov 12 '12 at 14:56
  • 1
    I'm guessing neither Windows Auth nor Forms auth is enabled. – MatthewMartin Nov 12 '12 at 15:15

1 Answers1

1

Try this :-

var username = this.Context.Request.LogonUserIdentity.Name;

If this doesn't work I think it must be your IIS Settings, as It works fine for me.

Derek
  • 8,300
  • 12
  • 56
  • 88