[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
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.
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.
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:
Public Class WebSitesInfo
' this class retreives the site names and the anonymous user for each
' site configured in IIS and returns an object that contains that data
Public Function GetSiteInfo(Optional ByVal Webserver As String = "localhost") As Collection
Dim retval As New Collection ' return value
Dim index As Integer = 1 ' site iterator
Dim VSvrObj As Object ' ADSI object
Dim tempSiteInfo As New SiteInfo ' place holder for the site information
Try
' prime the ADSI object
VSvrObj = GetObject("IIS://" & Webserver & "/W3SVC/" & index.ToString)
While Not VSvrObj Is Nothing
' get the anonymous username and the site it belongs to
' note: on winXP and 2000 pro there will be only one site
tempSiteInfo.SiteName = VSvrObj.ServerComment
VSvrObj = Nothing
VSvrObj = GetObject("IIS://" & Webserver & "/W3SVC/" & index.ToString & "/ROOT")
tempSiteInfo.SiteAnonUser = VSvrObj.AnonymousUserName
' add this site to the return collection
retval.Add(tempSiteInfo)
' advance the index
index += 1
' reset the ADSI object
VSvrObj = Nothing
' get the next site
VSvrObj = GetObject("IIS://LocalHost/W3SVC/" & index.ToString)
' reset the site information
tempSiteInfo = New SiteInfo
End While
Catch ex As Exception
' if there is an exception thrown fail gracefully
End Try
Return retval
End Function
Friend Class SiteInfo
' holds information for one web site
Private m_sSiteName As String
Private m_sSiteAnonUser As String
Public Property SiteName() As String
Get
Return m_sSiteName
End Get
Set(ByVal Value As String)
m_sSiteName = Value
End Set
End Property
Public Property SiteAnonUser() As String
Get
Return m_sSiteAnonUser
End Get
Set(ByVal Value As String)
m_sSiteAnonUser = Value
End Set
End Property
End Class
End Class