How to add new website into IIS Programmatically using C#?


Overview: Here I am writing an article for Creating website in IIS programmatically using c#.For Adding or deleting a website from IIS here, is this scenario I must say IIS7 is the best friend for the developers.

Because administering websites through the code was made very simple by Microsoft.Web.Administration.dll which is present in the %windir%system32inetsrv folder.IS 7.0 and above provide a comprehensive managed-code management application programming interface (API) that allows complete manipulation of the XML configuration files and convenience access to server objects.


IIS includes Microsoft.Web.Administration, which is a new a management API for the web server that enables editing configuration through complete manipulation of the XML configuration files.

It also provides convenience objects to manage the server, its properties and state. The configuration editing aspect of the API provides programmatic access to read and write configuration properties in the IIS configuration file hierarchy and specific configuration files.

The object management aspect of this API provides a series of top-level administration objects for the direct management of the server (i.e. sites, application pools, worker processes, etc).

Using ServerManager Namespace:

The ServerManager is the factory class that contains a set of server convenience objects to which properties and methods are available to use in a strongly-type way.

It is the main entry point for managing the server. Managing the server could have been done via other cumbersome routes (accessing raw configuration XML or calling state APIs), but through these objects managing the server is seamless.

The most common sets of objects are available to use via the server manager include applications, virtual directories, sites, worker processes and application domains



The sites object enables access to a sites properties and applications. It also contains methods to add a site to the system or get the total site count.

The add method also defines the name of the site, the root virtual directory path, and the port number as an integer.


  • Add Microsoft.web.Administration DLL.
  • Environment: IIS 7

Step by Step code to add website in IIS programmatically as given below:

Code : Page Default.apsx.cs



This article demonstrated one of the concepts to create a new website on IIS programmatically using ASP.NET and C#.


  • Make sure your redirection.config file has Read, Write full Permission.
  • It is just my experienced which is explained in the above article also it doesn’t include additional things like exception handling & web service security.Please feel to modify it according to your requirements.

Location: c: windowsSystem32 inetsrv config redirection.config;

You can also check these articles:

  1. Chart.js : Create Pie chart with database Jquery Ajax C#.
  2. Chart.js Create Line chart with database Jquery Ajax C#.
  3. Generic Handler ashx file : Post send JSON data in C#.
  4. jQuery Ajax JSON Example in with sql database.

Hope you enjoyed this tutorial. If you have any recommendations, please let us know what you think in the comment section below! See you again next time!