I have been trying to read the username of the user browsing my MVC application. The application doesn't have any authentication, and is hosted in IIS with windows authentication disabled and anonymous authentication enabled.
Now, I want to ensure that when a user is browsing the application then s/he doesn't see any popup for user credentials. So, i have disabled the windows authentication and enabled the anonymous authentication.
But i am not able to read the username. I have tried all the following approaches:
User.Identity.Name
System.Security.Principal.WindowsIdentity.GetCurrent().Name
System.Environment.UserName
But since my user isn't authenticated, i am not getting the correct results.
What i have achieved till now is that i am able to read the machine name of the user with the help of the following code:
I am reading the IP address with the following:
Request.UserHostName
And then, getting the machine name using the following:
IPAddress myIP = IPAddress.Parse(IP);
IPHostEntry GetIPHost = Dns.GetHostEntry(myIP);
List<string> compName = GetIPHost.HostName.ToString().Split('.').ToList();
return compName.First();
I tried searching for answers and got the following:
https://stackoverflow.com/a/1688220/2429125
But, even this wasn't of my help. Can someone point me to reading the username for a MVC application with no authentication with anonymous access?
Thanks,
Sudip Arora