WindowsPrincipal and aspnet user

Discussion in 'ASP .Net Security' started by william_dudek@yahoo.com, Jan 26, 2006.

  1. Guest

    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;
    , Jan 26, 2006
    #1
    1. Advertising

  2. 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;
    Dominick Baier [DevelopMentor], Jan 26, 2006
    #2
    1. Advertising

  3. 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]" <>
    wrote in message news:...
    > 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;

    >
    >
    Joe Kaplan \(MVP - ADSI\), Jan 26, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Burton

    WindowsPrincipal and WindowsIdentity.

    Kevin Burton, Jan 7, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    7,361
    bruce barker
    Jan 8, 2004
  2. Mark
    Replies:
    1
    Views:
    3,166
    qvo178
    Feb 23, 2010
  3. Peter Moberg

    Role empty in WindowsPrincipal

    Peter Moberg, Jul 25, 2003, in forum: ASP .Net Security
    Replies:
    0
    Views:
    132
    Peter Moberg
    Jul 25, 2003
  4. Mark

    CurrentPrincipal, WindowsPrincipal

    Mark, Jan 12, 2004, in forum: ASP .Net Security
    Replies:
    1
    Views:
    165
    zeldadog
    Jan 12, 2004
  5. naijacoder naijacoder

    WindowsPrincipal.IsInRole() problem with non-builtin roles

    naijacoder naijacoder, Aug 30, 2004, in forum: ASP .Net Security
    Replies:
    4
    Views:
    247
    Joe Kaplan \(MVP - ADSI\)
    Sep 2, 2004
Loading...

Share This Page