Any way to determine, via code, the user's Windows Login Name and domain?

Discussion in 'ASP .Net' started by Dave, Apr 20, 2005.

  1. Dave

    Dave Guest

    Greetings,

    I have a web application that will be hosted on our intranet. I would like
    to determine, via code the user's windows login name and domain in the
    following format: DOMAIN\loginname

    Is this possible? Thanks,

    -Dave
     
    Dave, Apr 20, 2005
    #1
    1. Advertising

  2. Yes, this is possible.
    Use Windows authentication in your web app, then examine the User object
    from your web page code. It should be WindowsPrincipal with WindowsIdentity,
    and with identity.Name set to windows account name.
    I might be wrong in some technical details as this is what I remember, but
    in general it works.

    Best regards
    Rafal Gwizdala

    "Dave" <> wrote in message
    news:%...
    > Greetings,
    >
    > I have a web application that will be hosted on our intranet. I would
    > like to determine, via code the user's windows login name and domain in
    > the following format: DOMAIN\loginname
    >
    > Is this possible? Thanks,
    >
    > -Dave
    >
     
    Rafal Gwizdala, Apr 20, 2005
    #2
    1. Advertising

  3. Dave

    Brad Guest

    Simplistically put, you need the following:
    1) In IIS console you need to set the Authentication method for the
    application folder to Integrated Windows Security (typically this is just
    unchecking anonymous access)
    2) Make sure the NT folder's security permissions allow access for the
    required users i.e. Authenticated Users...or at least the users / groups
    notes in next step
    3) In web.config enable impersonation <identity impersonate="true">
    And allow all users...or at least the domain users and/or groups who
    should have access
    i.e. <authorization>
    <allow users="*">
    </authorization>
    4) Use System.Security.Principal (vb Imports or c# Using)
    5) Get the name in code i.e.in vb
    ' get the domain\user name
    Dim userName As String = WindowsIdentity.GetCurrent.Name

    I would strongly reccomend you look at
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetlpmsdn.asp
    (can also get this as a book, which I highly reccomend)


    "Dave" <> wrote in message
    news:%...
    > Greetings,
    >
    > I have a web application that will be hosted on our intranet. I would
    > like to determine, via code the user's windows login name and domain in
    > the following format: DOMAIN\loginname
    >
    > Is this possible? Thanks,
    >
    > -Dave
    >
     
    Brad, Apr 20, 2005
    #3
  4. RE: Any way to determine, via code, the user's Windows Login Name and

    Hi Dave,

    Use following steps:

    1) In Web.Config file, set Windows authentication and deny anonymous:

    <authentication mode="Windows"/>
    <authorization>
    <deny users="?" /> <!-- deny anonymous -->
    <allow users="*" /> <!-- Allow all users -->
    </authorization>

    2) In code use:
    Page.User.Identity.Name
    It gives DOMAIN\loginname.

    HTH

    Elton Wang





    "Dave" wrote:

    > Greetings,
    >
    > I have a web application that will be hosted on our intranet. I would like
    > to determine, via code the user's windows login name and domain in the
    > following format: DOMAIN\loginname
    >
    > Is this possible? Thanks,
    >
    > -Dave
    >
    >
    >
     
    =?Utf-8?B?RWx0b24gVw==?=, Apr 21, 2005
    #4
  5. Dave

    Dave Guest

    Re: Any way to determine, via code, the user's Windows Login Name and

    Thank you everybody for the responses, I appreciate it. I will give them a
    try this morning.

    -Dave


    "Elton W" <> wrote in message
    news:...
    > Hi Dave,
    >
    > Use following steps:
    >
    > 1) In Web.Config file, set Windows authentication and deny anonymous:
    >
    > <authentication mode="Windows"/>
    > <authorization>
    > <deny users="?" /> <!-- deny anonymous -->
    > <allow users="*" /> <!-- Allow all users -->
    > </authorization>
    >
    > 2) In code use:
    > Page.User.Identity.Name
    > It gives DOMAIN\loginname.
    >
    > HTH
    >
    > Elton Wang
    >
    >
    >
    >
    >
    > "Dave" wrote:
    >
    >> Greetings,
    >>
    >> I have a web application that will be hosted on our intranet. I would
    >> like
    >> to determine, via code the user's windows login name and domain in the
    >> following format: DOMAIN\loginname
    >>
    >> Is this possible? Thanks,
    >>
    >> -Dave
    >>
    >>
    >>
     
    Dave, Apr 21, 2005
    #5
    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. William F. Robertson, Jr.
    Replies:
    0
    Views:
    473
    William F. Robertson, Jr.
    Jul 2, 2003
  2. Infant Newbie
    Replies:
    2
    Views:
    3,305
    Infant Newbie
    Nov 12, 2003
  3. Patrick

    Getting windows user-name without domain name

    Patrick, Dec 7, 2007, in forum: ASP .Net Security
    Replies:
    2
    Views:
    589
    Nikolay Podkolzin
    Dec 14, 2007
  4. Jonas Daunoravicius
    Replies:
    5
    Views:
    174
    Jonas Daunoravicius
    Jan 19, 2004
  5. Chem Leakhina
    Replies:
    2
    Views:
    232
    Robert Klemme
    Jun 23, 2009
Loading...

Share This Page