Solved

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

Posted on 2008-06-25
4
8,834 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

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

14 Experts available now in Live!

Get 1:1 Help Now