Solved

Username

Posted on 2011-03-03
11
244 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
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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now