Find the user name (and domain) for logged in user for in an internal intranet site
It was an old post, but helped me even after 15 years, this is how we can find the login user (and domain) of the logged in user in an internal intranet site.
Using ServerVariables.
Can use some work to show an error message if user is not logged in.
<%
CurrentAuth = Request.ServerVariables("AUTH_USER")
CurrentAuthType = Request.ServerVariables("AUTH_TYPE")
CurrentAuthUser = ""
CurrentAuthDomain = ""
If CurrentAuth = "" Then
If UCase(Request.ServerVariables("SERVER_NAME")) = UCase("Localhost") Then
CurrentAuthUser = "ANmar Developing"
CurrentAuthDomain = "Local"
End If
Else
CurrentAuthUser = CutString3(CurrentAuth, 2, "\")
CurrentAuthDomain = CutString3(CurrentAuth, 1, "\")
End If
'Force Authentication if the LOGON_USER Server Variable is blank by sending the Response.Status of 401 Access Denied.
'Finish the Page by issuing a Response.End so that a user cannot cancel through the dialog box.
If CurrentAuthUser = "" Then
Response.Status = "401 Access Denied"
Response.End
End If
% >
<HTML >
<HEAD > <TITLE >Login Screens </TITLE > </HEAD >
<BODY >
<B >Login Screens </B > <BR >
<HR SIZE="1" COLOR="#000000" >
You logged in as user: <B > <%= CurrentAuthUser % > </B >
<P >You were authenticated using: <B > <%= CurrentAuthType % > </B > authentication. </P >
</BODY >
</HTML >
CurrentAuth = Request.ServerVariables("AUTH_USER")
CurrentAuthType = Request.ServerVariables("AUTH_TYPE")
CurrentAuthUser = ""
CurrentAuthDomain = ""
If CurrentAuth = "" Then
If UCase(Request.ServerVariables("SERVER_NAME")) = UCase("Localhost") Then
CurrentAuthUser = "ANmar Developing"
CurrentAuthDomain = "Local"
End If
Else
CurrentAuthUser = CutString3(CurrentAuth, 2, "\")
CurrentAuthDomain = CutString3(CurrentAuth, 1, "\")
End If
'Force Authentication if the LOGON_USER Server Variable is blank by sending the Response.Status of 401 Access Denied.
'Finish the Page by issuing a Response.End so that a user cannot cancel through the dialog box.
If CurrentAuthUser = "" Then
Response.Status = "401 Access Denied"
Response.End
End If
% >
<HTML >
<HEAD > <TITLE >Login Screens </TITLE > </HEAD >
<BODY >
<B >Login Screens </B > <BR >
<HR SIZE="1" COLOR="#000000" >
You logged in as user: <B > <%= CurrentAuthUser % > </B >
<P >You were authenticated using: <B > <%= CurrentAuthType % > </B > authentication. </P >
</BODY >
</HTML >
Views 1,029
Downloads 403
CodeID
DB ID