Solved

How to get windows user ID in C# web application (asp.net 2.0)?

Posted on 2008-06-25
4
8,847 Views
Last Modified: 2013-11-07
How to get windows user ID in C# web application?
To clarify, I am talking about login ID that user uses to login to his working machine. (he/she has to press Ctrl-Alt-Del and enter login and password to start working)

I was looking around and  one of the suggestion was to use:  System.Environment.UserName;
But, this gives (by my opinion) account name under which the application is logged to the server that hosts application. In my case I get "ASPNET" and that is not my windows ID.

I assume that for this I will have to connect to Active Directory. How can I do that and how to query Active Directory. Thanks.
0
Comment
Question by:sacvb
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Chumad earned 65 total points
ID: 21869751
You'll need to disable anonymous access on the website.

Once you've got Anony turned off, you can see who the authenticated user:  Page.User.Identity.Name
0
 
LVL 8

Expert Comment

by:Chumad
ID: 21869755
string authUser = Page.User.Identity.Name;
0
 
LVL 18

Assisted Solution

by:carlnorrbom
carlnorrbom earned 60 total points
ID: 21869936
Hi,

Or You could use:

Request.LogonUserIdentity.Name.ToString 'will give you the logged on windows/domain account in DOMAIN\username format as string
Request.LogonUserIdentity.User.ToString 'will give you the domain SID of the logged on user as a string

/Carl.
0
 

Author Comment

by:sacvb
ID: 21875551
Thanks all
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

792 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