Get List of AppPools from IIS

故事扮演 提交于 2019-12-11 22:49:37

问题


I'm using vb.net 3.5 with asp.net and I need to list all AppPools names from IIS and show them in dropdownlist. any help please ?

thanks


回答1:


finally I found the solution and here is the methods it could help ..

Public Function GetAppPoolNames() As List(Of String)
    Dim Root As System.DirectoryServices.DirectoryEntry = GetDirectoryEntry("IIS://localhost/W3SVC/AppPools")
    'DirectoryEntry Root = new DirectoryEntry("IIS://localhost/W3SVC/1/Root");
    Dim AppList As New List(Of String)
    If Root Is Nothing Then

    Else
        For Each dir As DirectoryEntry In Root.Children
            Dim pr As System.DirectoryServices.PropertyCollection = dir.Properties
            'ApplicationPool pool = new ApplicationPool();
            'pool.Name = dir.Name;
            'DropDownList1.Items.Add(pool.Name);
            AppList.Add(dir.Name)
        Next

    End If
    Return AppList
End Function
Private Function GetDirectoryEntry(ByVal path As String) As DirectoryEntry
    Dim root As DirectoryEntry = Nothing
    Try
        root = New DirectoryEntry(path)
    Catch
        'Console.WriteLine("Could not access Node")
        Return Nothing
    End Try
    If root Is Nothing Then
        'Console.WriteLine("Could not access Node")
        Return Nothing
    End If
    Return root
End Function


来源:https://stackoverflow.com/questions/5962725/get-list-of-apppools-from-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!