Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Username

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
razza_b
Asked:
razza_b
1 Solution
 
John ClaesSenior .Net Consultant & Technical AnalistCommented:
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
 
AnilKumarSharmaCommented:
Yes but your application that get user name needs admin privileges.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
razza_bAuthor Commented:
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
 
pasoloCommented:
Environment.UserName (System.Environment)

is more strightforward
0
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
vandalesmCommented:
I agree with carl, you must use Window Authentication instead of Anonymous access.
0
 
TMWSIYCommented:
If this is a web app just use :

User.Identity.Name

Open in new window

0
 
razza_bAuthor Commented:
sorry guys not been @ work will update asap.
0
 
razza_bAuthor Commented:
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
 
TMWSIYCommented:
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
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now