WindowsPrincipal and aspnet user

W

william_dudek

I haven't been able to find a clear explanation on this one. Using
Visual Studio 2005, on my test environment (windows xp) the following
code returns the user who is logged into windows. However on the server
(Windows 2000 server service pack 4) it returns the aspnet account.
Both are set to disallow anonymous access and use Integrated
Windows authentication.

Any thoughts on how I can get the username of the person hitting the
website would be great.

The problem goes beyond this in that I need to check and see if
this user is part of a specific group on the machine, but my root cause
seems to be that I am not getting the correct user in the first place.


WindowsPrincipal wp = new
WindowsPrincipal(WindowsIdentity.GetCurrent());
string userName = wp.Identity.Name;
 
J

Joe Kaplan \(MVP - ADSI\)

Yes, the authenticated user is Context.User.

To elaborate a little more, WindowsIdentity.GetCurrent() returns the current
Windows security context. This may or may not be same as the authenticated
user, depending on whether or not you have enabled impersonation in your
web.config (and whether you are using Windows authentication at all). Note
that unless you need impersonation, there is no reason to enable it. If you
don't know if you need impersonation, you probably don't.

Joe K.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top