2011-12-08 44 views
0

目前越來越Unknown error (0x80005000) - 與運行下面的代碼 string virtualDirectory = GetVirtualDirPath("IIS://localhost", "1", reportUrl);DirectoryEntry.Properties [「Path」]。Value.ToString(); IIS7問題。 C#

static string GetVirtualDirPath(string iisHost, 
           string siteName, string vdName) 
    { 
     string adsiPath = iisHost + "/W3SVC/" + siteName + "/Root/test/" + vdName; 

     try 
     { 
      DirectoryEntry entry = new DirectoryEntry(adsiPath); 
      return entry.Properties["Path"].Value.ToString(); 
     } 
     catch (Exception ex) 
     { 
      // If Virtual Directory is not found, 
      // it will throw exception. 
      return ""; 
     } 

     return ""; 
    } 

我有安裝 「共享」 作爲內部的虛擬目錄 「/測試」(HTTP時, 「COM異常」 在C#中://本地主機/ test/share)並嘗試給該文件夾相關的權限。

我讀過,這隻適用於IIS6和不IIS7?如果是這樣,那麼等效代碼是什麼?

+0

看看這篇文章http://support.microsoft.com/kb/2428673,可以幫助你 –

回答

2

IIS7現在公開了一個託管管理API,其信息可以是found here

更具體地說,有一些類可以方便管理虛擬目錄。

var iis = new ServerManager(); 
var site = iis.Sites["SiteName"]; 
var application = site.Applications["ApplicationName"]; 
var directories = application.VirtualDirectories; 
//proceed to determine the physical path of appropriate directory 
var path = directories[0].Path; 
+0

@mrDisappointment - 看起來很有希望,該命名空間請問ServerManager的坐下?我會嘗試這種方法! – JustAnotherDeveloper