问题
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