How do I Programatically add a Web Site (C#) to IIS 6.0?

c#, iis, installation, web

Solution

we use a js windows script to update our virtual directories between branches, I would imagine that you could use the same objects to create a website

var iisPath = "IIS://localhost/W3SVC/" + siteID;
var site = GetObject(iisPath);

Microsoft has a fairly extensive article on configuring IIS 6 programatically. As long as your MSI can call a batch file, this article should help out.

This article also has a complete script file that creates a website.

Problem

We have a web application that until now installed under the "Default Web Site" in IIS. A customer now wants us to install it under a different web site, and we want to do that from the installer. My question is in 2 parts: A) How do I programatically add another web site alongside the 'default web site'? B) We are using Windows Installer - is there a way to trigger whatever code I write for section A from within the installer in time for the installation to take place at the new location? It looks like overriding Install() is too late in the game...

Original source

Related problems