Programatically Determine IIS User Account?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • controlbox
    New Member
    • Jan 2007
    • 6

    Programatically Determine IIS User Account?

    Does anyone know a way to programatically determine the Windows Account IIS is using from inside an ASP or ASP.Net page?
  • elmemo
    New Member
    • Apr 2007
    • 30

    #2
    Hi,

    At work I have used System.Security .Pricipal.Windo wsIdentity.GetC urrent()

    Remember though that the identity of secondary processes (say, those who use foreign dll's) might not have the same permissions as the original process acount, this is especially a recurring issue when dealing with network resources.

    You can enable impersonation of other user accounts if you need to. (refer to http://www.eggheadcafe .com/articles/20050703.asp )

    An excerpt from http://www.eggheadcafe .com/articles/20050703.asp is a good read:

    Determining Identity
    To determine the identity used for the request I set up a single aspx page that writes out the three most common ways of getting the current identity from a web application. These are the Page.User.Ident ity, System.Security .Pricipal.Windo wsIdentity.GetC urrent() and system.Threadin g.Thread.Curren tPrincipal.Iden tity. The code for the Page_Load event is displayed in Listing 1. The IIS Security Settings dialog can be seen in Figure 1. This displays the options available for configuring web security with IIS.
    Listing 1.


    private void Page_Load(objec t sender, System.EventArg s e)
    {
    lblUser.Text = Page.User.Ident ity.Name;
    lblWindow.Text = System.Security .Principal.Wind owsIdentity.Get Current().Name;
    lblThread.Text = System.Threadin g.Thread.Curren tPrincipal.Iden tity.Name;
    }

    Comment

    • controlbox
      New Member
      • Jan 2007
      • 6

      #3
      Many Thanks for the .Net solution. Do you know of a classic ASP solution?

      Comment

      • elmemo
        New Member
        • Apr 2007
        • 30

        #4
        Sorry, I'm a classic asp newbie!

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Originally posted by controlbox
          Does anyone know a way to programatically determine the Windows Account IIS is using from inside an ASP or ASP.Net page?
          If no one is logged on I think it is just <i_usr>, although I may have spelled it wrong. It may be in the server variables, try

          request.serverV ariables("logon _user")
          or
          request.serverV ariables("auth_ user")

          But I think those will be blank unless you require a logon, in which case IIS is using I_USER

          Jared

          Comment

          Working...