Getting the value of Request.ServerVariables(“LOGON_USER”)

3.9k Views Asked by At

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;
1

There are 1 best solutions below

1
On

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