Results 1 to 4 of 4

Thread: [RESOLVED] Anonymous User Account in IIS

  1. #1

    Thread Starter
    New Member SirPsycho's Avatar
    Join Date
    Aug 2005
    Location
    Albany, NY
    Posts
    7

    Resolved [RESOLVED] Anonymous User Account in IIS

    Is there a way to retreive the Anonymous User Account in IIS programatically (using .NET, Script, anything...)? I want to retreive the actual value and not resort to pulling the machine name and preceding it with 'IUSR_'

    Thanks in advance for the help

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Anonymous User Account in IIS

    Quote Originally Posted by SirPsycho
    Is there a way to retreive the Anonymous User Account in IIS programatically (using .NET, Script, anything...)? I want to retreive the actual value and not resort to pulling the machine name and preceding it with 'IUSR_'

    Thanks in advance for the help
    Scroll past the Syntax and Remarks in this link and take a look at the Example code. Its uses something called GetAnonymousUser() that may be what you are looking for.

  3. #3

    Thread Starter
    New Member SirPsycho's Avatar
    Join Date
    Aug 2005
    Location
    Albany, NY
    Posts
    7

    Re: Anonymous User Account in IIS

    Thank You, but not quite what I'm looking for. IIS must store the name of the anonymous user account somewhere that's accessable to programmers. I'm looking for some sort of an API call to the IIS system that you can pass a site name that you have set up ('Default Web Site' or 'www.somedomain.com') that exists in the IIS Snap-in that will return the 'Anonymous Access Acount' that has been set up for that particular site.

    I've seen a few examples of ADSI that allows programmatic administration of web sites in IIS, but nothing that deals with the anonymous user account attached to those sites. I'll keep looking and if I figure it out I'll post the outcome.

  4. #4

    Thread Starter
    New Member SirPsycho's Avatar
    Join Date
    Aug 2005
    Location
    Albany, NY
    Posts
    7

    Re: Anonymous User Account in IIS

    GOT IT! Here's a class I wrote (VB.NET - VS 2003) that iterates the sites configured in IIS and returns the site name and anonymous user associated with it in a collection of SiteInfo classes (also defined within the class). Here is the link I used with information that you can use to customize this class.

    http://www.microsoft.com/windows2000...e9l.htm?id=249

    VB Code:
    1. Public Class WebSitesInfo
    2.     ' this class retreives the site names and the anonymous user for each
    3.     ' site configured in IIS and returns an object that contains that data
    4.  
    5.  
    6.     Public Function GetSiteInfo(Optional ByVal Webserver As String = "localhost") As Collection
    7.         Dim retval As New Collection ' return value
    8.         Dim index As Integer = 1 ' site iterator
    9.         Dim VSvrObj As Object ' ADSI object
    10.         Dim tempSiteInfo As New SiteInfo ' place holder for the site information
    11.         Try
    12.             ' prime the ADSI object
    13.             VSvrObj = GetObject("IIS://" & Webserver & "/W3SVC/" & index.ToString)
    14.             While Not VSvrObj Is Nothing
    15.                 ' get the anonymous username and the site it belongs to
    16.                 ' note: on winXP and 2000 pro there will be only one site
    17.                 tempSiteInfo.SiteName = VSvrObj.ServerComment
    18.                 VSvrObj = Nothing
    19.                 VSvrObj = GetObject("IIS://" & Webserver & "/W3SVC/" & index.ToString & "/ROOT")
    20.                 tempSiteInfo.SiteAnonUser = VSvrObj.AnonymousUserName
    21.  
    22.  
    23.                 ' add this site to the return collection
    24.                 retval.Add(tempSiteInfo)
    25.                 ' advance the index
    26.                 index += 1
    27.  
    28.                 ' reset the ADSI object
    29.                 VSvrObj = Nothing
    30.                 ' get the next site
    31.                 VSvrObj = GetObject("IIS://LocalHost/W3SVC/" & index.ToString)
    32.                 ' reset the site information
    33.                 tempSiteInfo = New SiteInfo
    34.             End While
    35.         Catch ex As Exception
    36.             ' if there is an exception thrown fail gracefully
    37.         End Try
    38.  
    39.         Return retval
    40.     End Function
    41.  
    42.  
    43.     Friend Class SiteInfo
    44.         ' holds information for one web site
    45.         Private m_sSiteName As String
    46.         Private m_sSiteAnonUser As String
    47.         Public Property SiteName() As String
    48.             Get
    49.                 Return m_sSiteName
    50.             End Get
    51.             Set(ByVal Value As String)
    52.                 m_sSiteName = Value
    53.  
    54.             End Set
    55.         End Property
    56.  
    57.         Public Property SiteAnonUser() As String
    58.             Get
    59.                 Return m_sSiteAnonUser
    60.             End Get
    61.             Set(ByVal Value As String)
    62.                 m_sSiteAnonUser = Value
    63.             End Set
    64.         End Property
    65.  
    66.     End Class
    67. End Class
    Last edited by SirPsycho; Oct 21st, 2005 at 05:53 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width