Display Windows username in ASP.NET

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
You just want to display the UserName of the currently logged in user?

Something like that yes. It should display the name of the WINDOWS account logged onto the local machine, in an ASP.NET page... The name the user uses to log onto the local machine (Windows Authentication) must be displayed in an ASP.NET page...
 
I have managed to display the user's IP address, but still needs to display the USERNAME.

<%
Dim ipAddress As String
ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress
response.write(ipAddress)
%>

But when I try the following code, it displays NOTHING:

<%
Dim usrName As String
usrName = System.Web.HttpContext.Current.Current.User.Identity.Name
response.write(usrName)
%>
 
Using Context.User.Identity.Name should give you the Username of the user currently logged in.

Make sure your IIS Directory Security settings are set to Integrated Security only - don't allow Anonymous Access. I've had the same problem previously and that seemed to work for me.
 
I use Request.ServerVariables["AUTH_USER"]; as FarligOpptreden said, make sure that the directory is not using anonymous. I am often left tearing my hair out trying to work out why my code is not working only to realise that I had forgotten to remove the anonymous access on the directory.
 
Top
Sign up to the MyBroadband newsletter
X