wesley.groves 0 Newbie Poster

I have put together some vb.net code that creates a website and sets various properties, adds additional host headers; but I cannot get it to "check" the allow anonymous access checkbox or start the website. The anonymous user and password are set properly, but the checkbox remains unchecked to allow access under security settings. When starting the website, I get an access denied. I am using <identity impersonate="true" userName="ADMINUSER" password="ADMINPASSWORD"/> in my web.config.

Public Function CreateWebsite(ByVal webserver As String, ByVal serverComment As String, ByVal serverBindings As String, ByVal homeDirectory As String) As Integer

        Dim w3svc As DirectoryEntry
        w3svc = New DirectoryEntry("IIS://localhost/w3svc")

        'Create a website object array
        Dim newsite() As Object
        newsite = New Object() {serverComment, New Object() {serverBindings}, homeDirectory}

        'invoke IIsWebService.CreateNewSite
        Dim websiteId As Object
        websiteId = w3svc.Invoke("CreateNewSite", newsite)

        ' Get the newly created website

        websiteId.ToString()

        'Dim website As New DirectoryEntry(w3svc)

        'website.InvokeSet("AnonymousUserName", "domain.com\user")

        w3svc.InvokeSet("AnonymousUserName", "IUSR_MYCUISIN-E82264")
        ' set the anonymous(User)

        w3svc.InvokeSet("AnonymousUserPass", "6L9+k|P^F~1jQU")
        ' set theanonymous(Password)

        w3svc.InvokeSet("AuthAnonymous", True)

        w3svc.CommitChanges()

        StartWebsite(websiteId)

        AddHostHeader(ViewState("ServerName"), "www." & DomainName.Text, 80, websiteId)
End Function
Protected Sub StartWebsite(ByVal site_id As Integer)
        Dim location As String = "IIS://" & ViewState("ServerName") & "/W3SVC/" & site_id.ToString()
        Dim entry As New DirectoryEntry(location)
        entry.Invoke("start", New Object() {})
        entry.Close()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.