我正在使用vb.net 3.5和asp.net,我需要列出IIS中的所有AppPools名称并在下拉列表中显示它们。 有什么帮助吗?
感谢
答案 0 :(得分:1)
最后我找到了解决方案,这是它可以帮助的方法..
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