Tuesday, September 20, 2011

ASP : Displaying server variables


Sometimes you need to know who you are logged in as.

In the claims world, it’s easy because you have the IPrincipal and IIdentity objects but if these are not available, you need to go back to first principles.

Enter stage left the server variables. These are accessed from the Request object. A simple way to enumerate then all is via the html segment below which you just whack into an asp page.

<html>
    <body>
    
        <h1>ASP Request Variables Page</h1>

        <h2>
            The current user you are logged in as is: 
            <u>
                <!-- <%=Request.ServerVariables("AUTH_USER" & "<br />") %> -->
                
                <%= response.write("AUTH_USER" & "    " &  Request.ServerVariables("AUTH_USER") & "<br /><br />") %>
            <u>
        </h2>
                
            <%
                for each x in Request.ServerVariables
                    response.write(x & "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" &  Request.ServerVariables(x) & "<br /><br />")
                next
            %> 
            
    </body>

</html>

Enjoy!


No comments: