Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Username

Posted on 2011-03-03
11
Medium Priority
?
253 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:Rahul Agarwal
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

916 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