Solved

Username

Posted on 2011-03-03
11
249 Views
Last Modified: 2012-05-11
Hi Experts

Is this the best way to get the name of a user using an app on any machine?....

Label lblUsername = new Label();
lblUsername.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

im then inserting this data with other info into db.

Thanks
0
Comment
Question by:razza_b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35025648
0
 
LVL 10

Expert Comment

by:John Claes
ID: 35025654
this is indeed the Way ;-)

you're showing the Users windows Logon name in the textbox

http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.aspx

regards
poor beggar
0
 
LVL 9

Expert Comment

by:AnilKumarSharma
ID: 35025665
Yes but your application that get user name needs admin privileges.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Author Comment

by:razza_b
ID: 35025729
When i use in my dev env i get CORPORATE\name, but in live the saved user in db is
SR-PNG-WIP02\IUSR_SR-PNG-WIP02
0
 
LVL 3

Expert Comment

by:pasolo
ID: 35025799
Environment.UserName (System.Environment)

is more strightforward
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35025960
That would suggest that you are talking about a Web Application rather than a Desktop app. You must have anonymous access enabled for your site, which is causing the Identity of the account that IIS runs under to be returned, rather than the domain account that is accessing the site.

In IIS Admin, you need to switch off the Allow Anonymous Access option for the site.
0
 
LVL 1

Expert Comment

by:vandalesm
ID: 35026834
I agree with carl, you must use Window Authentication instead of Anonymous access.
0
 
LVL 6

Expert Comment

by:TMWSIY
ID: 35056668
If this is a web app just use :

User.Identity.Name

Open in new window

0
 
LVL 1

Author Comment

by:razza_b
ID: 35084490
sorry guys not been @ work will update asap.
0
 
LVL 1

Author Comment

by:razza_b
ID: 35108604
Hi Guys

I have tried all 3 of these and still no luck. What appears in db table sis below...

User.Identity.Name; = empty
System.Environment.UserName; = IUSR_SR-PNG-WIP02
System.Security.Principal.WindowsIdentity.GetCurrent().Name; = IUSR_SR-PNG-WIP02

Thanks
0
 
LVL 6

Accepted Solution

by:
TMWSIY earned 500 total points
ID: 35108783
IUSR_%computerName% is the users IIS uses for anonymous users.  If you want to capture the user name you need to enable impersonation.

Impersonate the IIS Authenticated Account or User:

To impersonate the Microsoft Internet Information Services (IIS) authenticating user on every request for every page in an ASP.NET application, you must include an <identity> tag in the Web.config file of this application and set the impersonate attribute to true. For example:
<identity impersonate="true" />

It seems that you have this set on your dev machine but not in production.

http://support.microsoft.com/kb/306158
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 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