Saturday, October 20, 2007

Request.ServerVariables (“LOGON_USER”) Error

Active Server Pages exposes an object called ServerVariables, which is part of the Request object. This ServerVariables object allows the programmer to see many environment variables. You can use the ServerVariables along with Internet Information Services (IIS)’s directory security options to determine who is currently accessing your site. You can also grab the visitor's IP address using the ServerVariables object.

In some .NET projects, when you try to access the Request.ServerVariables (“LOGON_USER”) variable in ASP .NET, it will return an empty string. This problem will occur due to the related authentication variables in the Server Variables list are not populated if you are using Anonymous Access Security to access the page. In the section of the Web.Config file, if you give the Anonymous user access, this problem will occur as well.

So how this problem can be solved?

There are two types of authentication mode which are Forms mode and Windows mode. To populate the LOGON_USER variable when you use any of the authentication mode other than none, you can deny access for Anonymous user in the section of the Web.Config file.

For authentication mode = “Forms”, use the following syntax in the Web.Config file.
< authorization >
< deny users = "?" > < !-- This denies access to the Anonymous user -- >
< allow users ="*" > < !-- This allows access to all users -- >
< /authorization >

If you are using Windows Authentication, go to Start > Run > Type inetmgr, this will bring IIS’s dialog box.

Expand Default Web Site and right click the Web Project folder, and then click Properties.

In the Properties dialog box, click the Directory Security tab, under the Anonymous access and authentication control, click Edit.

In the Authentication Methods dialog box, un-checked the Anonymous Access check box. Click OK for both dialog boxes. Close the IIS and does the testing again whether can get the value of LOGON_USER.

Hope this can help you work it out. Good luck.

0 comments:

 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
Sign up for PayPal and start accepting credit card payments instantly. http://www.emailcashpro.com
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template