Search code examples
c#iis-7iis-8

Add a application to IIS programmatically with default settings C#


I have a application that I would like to deploy programmatically with C# to IIS with default settings. Basically I would like to do what is in the screen shot below on a button click. Any help or guidance on this would be great.

enter image description here


Solution

  • This solved it for me. I was missing the

    using Microsoft.Web.Administration;
    
    ServerManager web = new ServerManager();
    web.Sites["Default Web Site"].Applications.Add("/Web", Drive + "/Portal/Web");
    web.Sites["Default Web Site"].Applications.Add("/WebAPI", Drive + "/Portal/WebAPI");
    web.CommitChanges();