简体   繁体   中英

Getting username in an mvc application with no authentication and anonymous authentication enabled in IIS

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

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM