Web application creation in IIS7 via MS.Web.Admin

Posted by Jon Ownbey on Stack Overflow See other posts from Stack Overflow or by Jon Ownbey
Published on 2010-04-12T20:09:16Z Indexed on 2010/04/12 20:13 UTC
Read the original article Hit count: 668

I am attempting to create seperate workflow instances as applications in IIS7 using the Microsoft.Web.Administration dll. When it attempts to add the Application to the Site ApplicationsCollection I get a COM error: "Invalid application path\r\n"

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();
            }

The value assigned to virtualPath is like: "something/something/something" and for physicalPath it is "c:\inetpub\wwwroot\Workflow\something\something\something". Any ideas?

Any help is greatly appreciated.

© Stack Overflow or respective owner

Related posts about iis7

Related posts about workflow-foundation-4