1

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

Community
  • 1
  • 1

2 Answers2

0

It is impossible to do so, as your current setup does not ask for any end user credentials.

You have to switch to forms authentication or Windows authentication at least.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
0

Can it be achieved without any sort of authentication

No. Why would a browser send the username of the visitor to every website they visit?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272