How can I look up IIS site id in C#?

后端 未结 5 2006
别跟我提以往
别跟我提以往 2020-12-28 22:49

I am writing an installer class for my web service. In many cases when I use WMI (e.g. when creating virtual directories) I have to know the siteId to provide the correct m

5条回答
  •  一整个雨季
    2020-12-28 23:11

    Maybe not the best way, but here is a way :

    1. loop through all the sites under "IIS://servername/service"
    2. for each of the sites check if the name is "Default Web Site" in your case
    3. if true then you have your site id

    Example :

    Dim oSite As IADsContainer
    Dim oService As IADsContainer
    Set oService = GetObject("IIS://localhost/W3SVC")
    For Each oSite In oService
        If IsNumeric(oSite.Name) Then
            If oSite.ServerComment = "Default Web Site" Then
                Debug.Print "Your id = " & oSite.Name
            End If
        End If
    Next
    

提交回复
热议问题