Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > WindowsPrincipal and aspnet user

Reply
Thread Tools

WindowsPrincipal and aspnet user

 
 
william_dudek@yahoo.com
Guest
Posts: n/a
 
      01-26-2006
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;

 
Reply With Quote
 
 
 
 
Dominick Baier [DevelopMentor]
Guest
Posts: n/a
 
      01-26-2006
Hi,

thats

Context.User.Identity.Name

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

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



 
Reply With Quote
 
 
 
 
Joe Kaplan \(MVP - ADSI\)
Guest
Posts: n/a
 
      01-26-2006
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.

"Dominick Baier [DevelopMentor]" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed). com...
> Hi,
> thats
>
> Context.User.Identity.Name
>
> ---------------------------------------
> Dominick Baier - DevelopMentor
> http://www.leastprivilege.com
>
>> 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;

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CurrentPrincipal, WindowsPrincipal Mark ASP .Net 1 02-23-2010 06:09 AM
WindowsPrincipal.IsInRole() problem with non-builtin roles naijacoder naijacoder ASP .Net Security 4 09-02-2004 01:56 AM
CurrentPrincipal, WindowsPrincipal Mark ASP .Net Security 1 01-12-2004 01:35 PM
WindowsPrincipal and WindowsIdentity. Kevin Burton ASP .Net 1 01-08-2004 01:20 AM
Role empty in WindowsPrincipal Peter Moberg ASP .Net Security 0 07-25-2003 05:00 AM



Advertisments