Microsoft KB Archive/306359

= PRB: Request.ServerVariables(&quot;LOGON_USER&quot;) Returns Empty String in ASP.NET =

Article ID: 306359

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft Internet Information Services 6.0
 * Microsoft ASP.NET 1.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q306359



SYMPTOMS
If you try to access the Request.ServerVariables(&quot;LOGON_USER&quot;) variable in ASP.NET, an empty string is returned.

NOTE: If you are using Microsoft Visual C# .NET, the following syntax accesses this variable: Request.ServerVariables[&quot;LOGON_USER&quot;]



CAUSE
This problem occurs because the authentication-related variables in the ServerVariables collection are not populated if you use Anonymous Access security to access the .aspx page. This problem can also occur if you give the Anonymous user access in the   section of the Web.config file.



RESOLUTION
To populate the LOGON_USER variable when you use any authentication mode other than None, you can deny access to the Anonymous user in the   section of the Web.config file. To deny access to the Anonymous user in the   section, follow these steps:   Change the authentication mode in the Web.config file to anything other than None. For example, the following entry in the Web.config file sets the authentication mode to Forms-based authentication:    To deny access to the Anonymous user in the Web.config file, use the following syntax:   

If you are using Windows authentication, you can also use the following steps to resolve this problem:   Change the authentication mode in the Web.config file to Windows as follows:  </li> In the Internet Services Manager, right-click the .aspx file or the Web Project folder, and then click Properties.</li> If you clicked Properties for the Web Project folder, click the Directory Security tab. If you clicked Properties for the .aspx file, click the File Security tab.</li> Under Anonymous Access and authentication control, click Edit.</li> In the Authentication methods dialog box, clear the Anonymous Access check box, and then select either the Basic, the Digest or the Integrated (NT Challenge/Response) check box.</li> Click OK to close both dialog boxes.</li></ol>

For instructions on how to configure Digest authentication, refer to the &quot;References&quot; section at the end of this article.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

MORE INFORMATION
ASP.NET provides new authentication modes and authorization schemes, which you can configure in the .config files. For this reason, modifying the authentication modes in IIS alone may not always yield the desired results. Therefore, you must also consider the security settings in the .config files.

NOTE: When you enable Anonymous authentication in conjunction with Windows authentication or if you grant access to the Anonymous user in the   section while you are using any authentication mode other than None, other server variables such as AUTH_USER and REMOTE_USER (as well as the HttpContext.Current.User.Identity.Name property) also return an empty string. You can use the any of the above-mentioned resolutions to populate these variables.

In ASP.NET, you can also use the IsAuthenticated property of the Request object to determine whether the Anonymous Access security is being used. IsAuthenticated returns &quot;false&quot; if Anonymous Access is turned on and returns &quot;true&quot; if you use any other means of authentication such as Forms, Passport, Integrated (NT Challenge/Response), or Basic.

<div class="references_section">