Microsoft Knowledge Base Email Alertz

This step-by-step guide explains the correct ASP syntax for retrieving user authentication information from a Web site visitor. This information can only be captured if the site uses Basic Authentication, Windows NT Challenge Response (NTL

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 299984 - Last Review: July 7, 2008 - Revision: 6.1

How To Use ASP to Retrieve Authentication Information About Web Users in IIS

This article was previously published under Q299984
We strongly recommend that all users upgrade to Microsoft Internet Information Services (IIS) version 7.0 running on Microsoft Windows Server 2008. IIS 7.0 significantly increases Web infrastructure security. For more information about IIS security-related topics, visit the following Microsoft Web site:
http://www.microsoft.com/technet/security/prodtech/IIS.mspx (http://www.microsoft.com/technet/security/prodtech/IIS.mspx)
For more information about IIS 7.0, visit the following Microsoft Web site:
http://www.iis.net/default.aspx?tabid=1 (http://www.iis.net/default.aspx?tabid=1)

On This Page

SUMMARY

This step-by-step guide explains the correct ASP syntax for retrieving user authentication information from a Web site visitor.

NoteThis information can only be captured if the site uses Basic Authentication, Windows NT Challenge Response (NTLM), or Windows Integrated Authentication.

Requirements

  • A Windows server that runs Internet Information Services (IIS) 4.0 or later
  • A text or ASP editor such as Notepad or Microsoft Visual InterDev


The Code

To capture the visitor's domain and login, paste the following code into your ASP page. If the page also contains HTML, paste this code above the HTML tag.
<%
Dim strUser
strUser = Request.ServerVariables("LOGON_USER")
Response.Write strUser
%>
This code will capture the user's domain and login, and then display it in the browser.

Making the Code More Useful

Now that you have a method for capturing the user's login information, you may want to store it somewhere. The steps in this section demonstrate how to create a text file and write the information to it. Note that this method is only one of many that use Request.ServerVariables.
  1. Right-click Start, and then click Explore to open Windows Explorer.
  2. In Windows Explorer, click File, point to New, and then click Folder.
  3. This will create a new folder with the name area highlighted. Type ASP, and then press ENTER to name the new folder "ASP."
  4. Paste the following code into your ASP page. If the page also contains HTML, paste this code above the HTML tag.
    <%
    Dim objFSO, strUser, objFile
    strUser = Request.ServerVariables("LOGON_USER")
    set objFSO = Server.CreateObject("scripting.FileSystemObject")
    set objFile = objFSO.CreateTextFile("C:\asp\test.txt", true)
    objFile.WriteLine strUser
    objFile.Close
    Response.Write strUser
    %>
    					
  5. This code will write the user's login information to a text file that is automatically created in the ASP folder (the folder you created in step 3).

APPLIES TO
  • Microsoft Internet Information Server 4.0
  • Microsoft Internet Information Services 5.0
  • Microsoft Internet Information Services 6.0
  • Microsoft Internet Information Services 7.0
Keywords: 
kbhowtomaster KB299984
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate