|Programmatically Manage IIS with C#

Microsoft Web Administration (MWA) is an extremely useful library that allows you to manage an IIS application programmatically – either from the same server or remotely. However, referencing this library can be a confusing process full of pitfalls.

The first trap is the extremely popular NuGet package – which should be avoided at all costs. Initially published by a random developer, this package has since been taken over by Microsoft – however, it is still not likely what you want.The NuGet package includes all of the dependencies for the package – which are included in IIS.

Setup Dependent Features

Before we get started, you must ensure that you have IIS Management Console installed on whatever machine you are running your application.

To do this on a windows machine, you can run the following from a command prompt:

dism.exe /enable-feature /online /featurename:IIS-ManagementConsole⁠

From Windows server, you can run the following PowerShell:

Add-WindowsFeature Web-Mgmt-Console

Add Assembly Reference

After the dependent feature is installed, a copy of the Microsoft.Web.Administration.dll will be created in the following location:


We need to add a reference to this library so that regardless of where your application is run, it will find the correct version.In Visual Studio, add a reference to this file normally. Then, close Visual Studio and open your project file (.csproj) in a text editor.The service account used to run your web application must have read access to the following folder:


If you are attempting to manage an IIS Server remotely, 

The version bundled with IIS Express is where the full version of IIS comes with, which can be extremely confusing.

The version bundled with IIS Express is where the full version of IIS comes with, which can be extremely confusing.This is complicated if you have a build server that has IIS Express installed – b/c it may include that instead of the full version.IIS on Builder Server…Relatedhttps://docs.microsoft.com/en-us/iis/develop/extending-the-management-ui/overview-of-mwa-and-mwm-for-iishttps://stackoverflow.com/questions/27166276/microsoft-web-administration-assembly-error-on-azurehttps://docs.microsoft.com/en-us/iis/develop/extending-iis-configuration/extending-iis-schema-and-accessing-the-custom-sections-using-mwahttps://blog.lextudio.com/whats-microsoft-web-administration-and-the-horrible-facts-you-should-know-b82f2c974da6https://stackoverflow.com/questions/28432807/servermanager-openremote-error-80040154-clsid-2b72133b-3f5b-4602-8952-803546ce3https://stackoverflow.com/questions/18104151/how-to-reference-microsoft-web-administrationhttp://mvolo.com/connecting-to-iis-70-configuration-remotely-with-microsoftwebadministration/https://www.codeproject.com/Articles/99634/%2fArticles%2f99634%2fUse-C-to-manage-IIS


To add a comment, please login or register.