Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SystemInformation.UserName 1

Status
Not open for further replies.

markknowsley

Programmer
Aug 30, 2005
152
GB
When I run

lblUserName.Text = SystemInformation.UserName;

the label displays ASPNET as the User Name.

I would like it to return my login name (and, even better, the login name for the users who will be using the form) so how do I do this?
 
Code:
using System.Security.Principal;
...
      WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
      CurrentUser = wp.Identity.Name;
...


_____
Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
That returns:

MACHINENAME/ASPNET

The thing is, I can match a machine name against the owner in our asset database so that's not necessarily the end of the world.

Maybe I could save a small text file onto the machine when the user first uses the form and then use this file to check Active Directory - does this sound a little far fetched?
 
When I use

Code:
Environment.UserName

I get the name of the signon that I used at this workstation.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
If you're doing a web app, your clients are simply getting a web pages in a browser. The web server is the machine actually querying your database (or doing whatever) which is why the only ID the DB server will see is the webserver's.

As far as I know you would have to have ActiveX or similar object installed on each client machine that could relay the Windows logon to the web page. I'm not aware of any JavaScript that could pull the Windows logon.

_____
Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
Ok, tried:

System.Environment.Username;

but that also returns ASPNET.
 
1) Within a web application you can get the current user with HttpContext.Current.User.
There are major drawbacks to this as the "Anonynmous access" must be disabled for that site and also Integrated Windows authentication must be enabled (you can find bot in IIS config tool).

2) Moreover, I think the IE must be set up to send the credentials from Tools -> InternetOptions -> Security -> Custom Level -> User Authentication -> Automatic Logon (or Automatic Logon with current user and password - you might want to experiment with this).

I am not sure about 2), but it seems the logical think to do.
 
Thanks a lot for this all - lots of useful information. I will let you know how I get on.
 
B00gyeMan,

As my post indicated, I wasn't aware you could do that with a web page. I might be able to find a use for that on my Intranet.

_____
Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top