Script behind page not pulling data when served from IIS7.5 (works in IIS6 and in Debug) RRS feed

  • Question

  • User-131142063 posted

    EDIT: Found the issue! In IIS7.5, in Authentication, I had to disable Anonymous Authentication and enable Windows Authentication. Success!

    Hi there!

    We have moved a website from IIS6 to IIS7.5 and it no longer seems to work. The specific part which fetches the user's AD alias doesn't seem to be firing any more, and this impacts on our welcome message and various other user-specific parts of the page.

    I've chopped the script down and isolated the specific part of the script which isn't firing. Simply put, it works when served from IIS6 and when debugging in Visual Studio 2010.

    The code is as follows:

    <%@ Page Language="VB" %>
    <!DOCTYPE html>
    <script runat="server">
        'Request one by name
        Public strNTUser As String
        Public iPos As Integer
        Public Function GetServerVariable(ByVal VariableName As String) As String
            Return Request.ServerVariables(VariableName)
        End Function
        'You may prefer to just focus on a few of interest
        'by hard coding their names in a function such as below
        Public Function ApplicationPath() As String
            Return Request.ServerVariables("APPL_PHYSICAL_PATH")
        End Function
        Public Function LoggedOnUser() As String
            Return Request.ServerVariables("LOGON_USER")
        End Function
        Public Function CurrentPage() As String
            Return Request.ServerVariables("SCRIPT_NAME")
        End Function
        Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            strNTUser = RTrim(GetServerVariable("LOGON_USER"))
            iPos = Len(strNTUser) - InStr(1, strNTUser, "\", 1)
            strNTUser = Right(strNTUser, iPos)
        End Sub
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <form id="form1" runat="server">
        <% Response.Write(strNTUser)%>

    Is there any reason why IIS7.5 isn't able to pull through (or pass through?) the information from the script, back to the web page to be served?

    I'm baffled. Your assistance is much appreciated. This is crossposted over at the asp.net forums (http://forums.asp.net/p/1942235/5533334.aspx) because I'm not sure where the problem lies.


    Friday, October 11, 2013 8:17 AM


  • User690216013 posted

    As you found out, the root cause is your code. When it tries to read ServerVariables("LOGON_USER") it won't get the result expected if anonoymous authentication is enabled. You can in fact compare the value of that variable in both cases to learn the details better.

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Friday, October 11, 2013 11:58 PM