2010-04-12 71 views
0

我試圖在IIS7中使用Microsoft.Web.Administration dll創建單獨的工作流實例作爲應用程序。當它試圖將應用程序添加到網站ApplicationsCollection我得到一個COM錯誤:「無效的應用程序路徑\ r \ n」個在IIS7中通過MS.Web.Admin創建Web應用程序

using (ServerManager manager = new ServerManager()) 
      { 
       var site = manager.Sites.Where(x => x.Name == Properties.Settings.Default.WorkflowWebsiteName).Single(); 

       StringBuilder stringBuilder = new StringBuilder() 
        .Append(m_workflowDefinition.AccountId) 
        .Append("/") 
        .Append(m_workflowDefinition.WorkflowDefinitionId) 
        .Append("/") 
        .Append(m_workflowDefinition.Version) 
        .Append("/"); 

       string virtualPath = stringBuilder.ToString(); 
       string physicalPath = Properties.Settings.Default.ApplicationPoolString + 
             virtualPath.Replace("/", "\\"); 

       if (!Directory.Exists(physicalPath)) Directory.CreateDirectory(physicalPath); 

       //Create the workflow service definition file 
       using (StreamWriter writer = new StreamWriter(Path.Combine(physicalPath, m_workflowDefinition.WorkflowName + WORKFLOW_FILE_EXTENSION))) 
       { 
        writer.Write(m_workflowDefinition.Definition); 
       } 

       //Copy dependencies      
       string dependencyPath = m_workflowDefinition.DependenciesPath; 
       CopyAll(new DirectoryInfo(dependencyPath), new DirectoryInfo(physicalPath)); 

       //Create a new IIS application for the workflow 
       var apps = site.Applications.Where(x => x.Path == virtualPath); 
       if (apps.Count() > 0) 
       { 
        site.Applications.Remove(apps.Single()); 
       } 
       Application app = site.Applications.Add(virtualPath, physicalPath); 

       app.ApplicationPoolName = "Workflow AppPool"; 
       app.EnabledProtocols = PROTOCOLS; 

       manager.CommitChanges(); 
      } 

分配給virtualPath的值是這樣的:「東西/某事/某事」和physicalPath它是「c:\ inetpub \ wwwroot \ Workflow \ something \ something \ something」。有任何想法嗎?

任何幫助,非常感謝。

回答

1

嘗試將您的「某物/某物/某物」路徑更改爲「/某物/某物/某物」。 IIS管理調用在路徑開始處需要額外的斜槓。

+0

謝謝!這正是問題所在。 – 2010-04-13 14:37:58