Getting Network User Name

  • Thread starter Thread starter Dave Bailey
  • Start date Start date
D

Dave Bailey

I am trying to obtain the Windows logon user name from my
local machine for use in a web app. I have added
<identity impersonate="true" /> to the Web.Config file.
This returns the IUSR user name. I am using the following
code to obtain the user name:

return System.Environment.UserName;

Can anyone point me in another direction to obtain the
windows login user name?

Thanks,

Dave
 
Dave,

The IUSR name is the name of the account that the process is running
under. This is correct for that call.

The thing is, do you have a user that is logged into your app? You need
to set the authentication mode to windows as well with the following
element:

<authenication mode="Windows"/>

Once you do that, and you set impersonation to true, you should be able
to get the user through the User property on the Page class, or from the
User property on the current HttpContext (the Page just aggregates the call
from the context).

Hope this helps.
 
Try using Request.ServerVariables[Auth_User]. I know this
works on an NT 4.0 domain with with anonymous logons
disabled in IIS. It is very important the anonymous
logons are disabled for this to work, otherwise you get
nothing.
 
It should not return IUSR_xxxxx, it should return the identity of the aspnet
worker process ('aspnet' by default).

Willy.
 
Nicholas,
IUSR is not used for asp.net applications , it's the impersonation account
for anonymous users touching in-proc ASP applications, ASP.NET (the
aspnet_wp.exe) runs with a different identity (aspnet by default).

Willy.

Nicholas Paldino said:
Dave,

The IUSR name is the name of the account that the process is running
under. This is correct for that call.

The thing is, do you have a user that is logged into your app? You need
to set the authentication mode to windows as well with the following
element:

<authenication mode="Windows"/>

Once you do that, and you set impersonation to true, you should be able
to get the user through the User property on the Page class, or from the
User property on the current HttpContext (the Page just aggregates the call
from the context).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dave Bailey said:
I am trying to obtain the Windows logon user name from my
local machine for use in a web app. I have added
<identity impersonate="true" /> to the Web.Config file.
This returns the IUSR user name. I am using the following
code to obtain the user name:

return System.Environment.UserName;

Can anyone point me in another direction to obtain the
windows login user name?

Thanks,

Dave
 
Hi Dave,

This is what you have to do:

In web.config :
<authentication mode="Windows"/>

<identity impersonate="true"/>


Then you can access the user from your application using this code:
WindowsIdentity.GetCurrent().Name

You will need to include System.Security.Principal namespace



Hope this help,
 
Back
Top