Retrieving username

Posted on 2013-05-27
Medium Priority
Last Modified: 2013-06-03
I have workstations with a variable that gives the logged on user id, how can I retrieve this value through a dot.net asp web application, that I am developing ?

The web server resides in a different domain from the users and there is also no trust between the domains, I have the anonymous IIS account setup for the web app, however using other methods, this is the value that is returned for the logged on user.

I would also be looking to take the user id and do a lookup on it in AD, so I can use the First name, second name values within AD.

I'm using VB.net with Visual Web Developer.

Any ideas ?
Question by:ndr-itsolutions

Expert Comment

ID: 39199122
TextBox6_AddDataControl1.Text = Request.ServerVariables("LOGON_USER")

Author Comment

ID: 39199135
Still get the same result, that is, the code returns the anonymous user account of the IIS server and not the username of the logged on user's workstation.

Accepted Solution

EddyvanOpdorp earned 1500 total points
ID: 39199433
See here: http://forums.asp.net/t/1179997.aspx

In ASP.NET, please use User.Identity.Name to get the logon user. User.Identity.Name might be empty if Anonymous Authentication is enabled in IIS.


Here is the logical to check if the identity is available.


' Gets the name if authenticated.
If User.Identity.IsAuthenticated Then
    Label1.Text = User.Identity.Name
    Label1.Text = "No user identity available."
End If


' Gets the name if authenticated.
if (User.Identity.IsAuthenticated)
    Label1.Text = User.Identity.Name;
    Label1.Text = "No user identity available.";

Environment.UserName is the running thread identity. If you have enabled Impersonation as Mark said, you can find out the returning result will be different. However this requires ASP.NET Impersionation. If you don't need ASP.NET Impersonation and dealing with the thread identity, you can ignore Environment.UserName if and just use User.Identity.Name.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question