0

I'm trying to get authenticated username in my ASP.NET page using Request.ServerVariables(“LOGON_USER”) variable. It gives me an empty string. There are a lot of topics about this variable. The common point is using an authentication type other than None and denying anonymous access. So I added these lines in my web.config:

<authentication mode="Forms"/>
<authorization>
  <deny users = "?" /> <!-- This denies access to the Anonymous user -->
  <allow users ="*" /> <!-- This allows access to all users -->
</authorization>

I still get an empty string. How can I get the username?

Also tried:

Request.ServerVariables["REMOTE_USER"];
Request.ServerVariables["UNMAPPED_REMOTE_USER"];
Request.ServerVariables["AUTH_USER"];
HttpContext.Current.User.Identity.Name;
Ned
  • 1,055
  • 9
  • 34
  • 58

1 Answers1

1

Finally fixed. You should disable anonymous access in IIS if you want to use Request.ServerVariables(“LOGON_USER”).

PS: Disabling anonymous access has some side effects such as infinite login redirect loop

Community
  • 1
  • 1
Ned
  • 1,055
  • 9
  • 34
  • 58
  • Check the properties in your web project file. There are settings for IIS in the project. See: https://stackoverflow.com/questions/9743550/iis-express-is-automatically-disabling-anonymous-authentication-for-my-project – Mike Nov 23 '20 at 19:17