uncategorized

顯示IIS站台列表的實體位置路徑

當我們需要管理很多台Server中的每個Web Site時日子久了難免會忘記該Web Site對應虛擬目錄路徑,因該這次透過顯示IIS所有站台列表方式,我們可以找到每個網站所對應的虛擬目錄位址

  1. 首先還是需要找出IIS中的每個網站及下面的虛擬目錄。前端程式碼可以參考顯示IIS所有站台列表作法
  2. 使用DirectoryEntryProperties屬性就可以找到其對應虛擬目錄位址。
    Properties:是取得DirectoryEntry的 Active Directory 屬性。

程式碼如下

1
2
3
4
5
6
7
8
static string GetVirtualDirPath(string siteName, string vdName)
{
string stringPath = string.Format(@"IIS://HostName/W3SVC/{0}/root/{1}", siteName,vdName);
DirectoryEntry entry = new DirectoryEntry(stringPath);
return entry.Properties["Path"].Value.ToString();
}