C# – Create Virtual Directories in IIS 7.5

asp.netciis-7.5virtual-directory

My asp.net web application knows how to create sub-applications (asp.net applications with web.config file, located in sub folders of the root application).

Now, I need to configure each sub-application in the IIS with a Virtual Directory, AND, make this new virtual directory an application in a specified application pool.

Is there any API for IIS7.5 using .NET ?

Best Answer

You could use Microsoft.Web.Administration which comes with IIS >= 7.0

There is a similar question here on SO: creating Virtual directory in IIS 7.0 using c#.net
The link provided in the first answer shows how to create virtual directory using the old Metabase API (used in IIS Versions prior to 7.0) and another method that uses appcmd.exe. appcmd is the command line version of the Microsoft.Web.Administration API.

An example that uses the API directly (IMO the best approach), can be found here: How to Use Microsoft.Web.Administration