Getting the current Windows user name

Discussion in 'ASP .Net' started by Nick, Jul 22, 2004.

  1. Nick

    Nick Guest

    I'm developing an intranet app, and want to get the current user name for
    logging purposes. I've turned off anonymous access, and turned on windows
    authentication in the IIS config. The apps web.config file has
    authentication mode set to windows, and 'identity impersonate' is set to
    true.

    When I try and get the default.aspx page, IE returns an error page with an
    'Access is denied.' error. (Even if I try direct from the webserver, logged
    on as the administrator.)

    Where else do I have to set the permissions?

    Thanks,

    Nick

    PS: I'm using this line in the code to get the user:
    System.Security.Principal.WindowsIdentity.GetCurrent().Name() - Is this the
    right one to use?
     
    Nick, Jul 22, 2004
    #1
    1. Advertising

  2. Nick

    Dale Guest

    Check your NTFS permissions (ACLs) to make sure the user trying to access
    the folder and files have access.

    Dale

    "Nick" <> wrote in message
    news:...
    > I'm developing an intranet app, and want to get the current user name for
    > logging purposes. I've turned off anonymous access, and turned on windows
    > authentication in the IIS config. The apps web.config file has
    > authentication mode set to windows, and 'identity impersonate' is set to
    > true.
    >
    > When I try and get the default.aspx page, IE returns an error page with an
    > 'Access is denied.' error. (Even if I try direct from the webserver,

    logged
    > on as the administrator.)
    >
    > Where else do I have to set the permissions?
    >
    > Thanks,
    >
    > Nick
    >
    > PS: I'm using this line in the code to get the user:
    > System.Security.Principal.WindowsIdentity.GetCurrent().Name() - Is this

    the
    > right one to use?
    >
    >
     
    Dale, Jul 22, 2004
    #2
    1. Advertising

  3. Nick

    Greg Burns Guest

    From a webform inheriting from Page class:
    Dim sCurrentuser As String = Me.User.Identity.Name

    From a class not inheriting from Page:
    Dim sCurrentuser As String = HttpContext.Current.User.Identity.Name

    Do these:
    Turn off anonymous access
    turn on window authentication in IIS
    web.config autentication mode set to windows

    Not required to do this
    Setting Identity Impersonate = True <-- this might be why getting Access
    denied to Virtual directory on IIS

    HTH,
    Greg


    "Nick" <> wrote in message
    news:...
    > I'm developing an intranet app, and want to get the current user name for
    > logging purposes. I've turned off anonymous access, and turned on windows
    > authentication in the IIS config. The apps web.config file has
    > authentication mode set to windows, and 'identity impersonate' is set to
    > true.
    >
    > When I try and get the default.aspx page, IE returns an error page with an
    > 'Access is denied.' error. (Even if I try direct from the webserver,

    logged
    > on as the administrator.)
    >
    > Where else do I have to set the permissions?
    >
    > Thanks,
    >
    > Nick
    >
    > PS: I'm using this line in the code to get the user:
    > System.Security.Principal.WindowsIdentity.GetCurrent().Name() - Is this

    the
    > right one to use?
    >
    >
     
    Greg Burns, Jul 22, 2004
    #3
  4. Nick

    Nick Guest

    Thanks for the suggestions - that seems to have done the trick!

    One difference though - on my XP Pro Dev PC I have to give the ASPNET user
    the database permissions for the pages to work. On the Win2k Server I need
    to give the IWAM_ user the db permissions. Is this right?

    Nick

    "Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
    news:...
    > From a webform inheriting from Page class:
    > Dim sCurrentuser As String = Me.User.Identity.Name
    >
    > From a class not inheriting from Page:
    > Dim sCurrentuser As String = HttpContext.Current.User.Identity.Name
    >
    > Do these:
    > Turn off anonymous access
    > turn on window authentication in IIS
    > web.config autentication mode set to windows
    >
    > Not required to do this
    > Setting Identity Impersonate = True <-- this might be why getting Access
    > denied to Virtual directory on IIS
    >
    > HTH,
    > Greg
    >
    >
    > "Nick" <> wrote in message
    > news:...
    > > I'm developing an intranet app, and want to get the current user name

    for
    > > logging purposes. I've turned off anonymous access, and turned on

    windows
    > > authentication in the IIS config. The apps web.config file has
    > > authentication mode set to windows, and 'identity impersonate' is set to
    > > true.
    > >
    > > When I try and get the default.aspx page, IE returns an error page with

    an
    > > 'Access is denied.' error. (Even if I try direct from the webserver,

    > logged
    > > on as the administrator.)
    > >
    > > Where else do I have to set the permissions?
    > >
    > > Thanks,
    > >
    > > Nick
    > >
    > > PS: I'm using this line in the code to get the user:
    > > System.Security.Principal.WindowsIdentity.GetCurrent().Name() - Is this

    > the
    > > right one to use?
    > >
    > >

    >
    >
     
    Nick, Jul 22, 2004
    #4
  5. Nick

    Greg Burns Guest

    I have the same setup (Win XP Pro for development & Win 2K Server for
    deployment) and I only have to give ASPNET user modify permissions to
    database folder.

    Download Filemon from here:
    http://www.sysinternals.com/

    Run it on your server, and see what is happening.

    Good luck,
    Greg

    "Nick" <> wrote in message
    news:...
    > Thanks for the suggestions - that seems to have done the trick!
    >
    > One difference though - on my XP Pro Dev PC I have to give the ASPNET user
    > the database permissions for the pages to work. On the Win2k Server I need
    > to give the IWAM_ user the db permissions. Is this right?
    >
    > Nick
    >
    > "Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
    > news:...
    > > From a webform inheriting from Page class:
    > > Dim sCurrentuser As String = Me.User.Identity.Name
    > >
    > > From a class not inheriting from Page:
    > > Dim sCurrentuser As String = HttpContext.Current.User.Identity.Name
    > >
    > > Do these:
    > > Turn off anonymous access
    > > turn on window authentication in IIS
    > > web.config autentication mode set to windows
    > >
    > > Not required to do this
    > > Setting Identity Impersonate = True <-- this might be why getting Access
    > > denied to Virtual directory on IIS
    > >
    > > HTH,
    > > Greg
    > >
    > >
    > > "Nick" <> wrote in message
    > > news:...
    > > > I'm developing an intranet app, and want to get the current user name

    > for
    > > > logging purposes. I've turned off anonymous access, and turned on

    > windows
    > > > authentication in the IIS config. The apps web.config file has
    > > > authentication mode set to windows, and 'identity impersonate' is set

    to
    > > > true.
    > > >
    > > > When I try and get the default.aspx page, IE returns an error page

    with
    > an
    > > > 'Access is denied.' error. (Even if I try direct from the webserver,

    > > logged
    > > > on as the administrator.)
    > > >
    > > > Where else do I have to set the permissions?
    > > >
    > > > Thanks,
    > > >
    > > > Nick
    > > >
    > > > PS: I'm using this line in the code to get the user:
    > > > System.Security.Principal.WindowsIdentity.GetCurrent().Name() - Is

    this
    > > the
    > > > right one to use?
    > > >
    > > >

    > >
    > >

    >
    >
     
    Greg Burns, Jul 22, 2004
    #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. Mike Newton
    Replies:
    0
    Views:
    2,898
    Mike Newton
    Jul 23, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,620
    Steve C. Orr [MVP, MCSD]
    Jul 23, 2004
  3. nalbayo
    Replies:
    2
    Views:
    5,506
    Bruce Barker
    Nov 11, 2005
  4. mpnordland
    Replies:
    24
    Views:
    895
  5. Patrick

    Getting windows user-name without domain name

    Patrick, Dec 7, 2007, in forum: ASP .Net Security
    Replies:
    2
    Views:
    541
    Nikolay Podkolzin
    Dec 14, 2007
Loading...

Share This Page