|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:

C:\Windows\System32\inetsrv\Microsoft.Web.Administration.dll

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:

C:\Windows\System32\inetsrv\config

If you are attempting to manage an IIS Server remotely, 

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

The version bundled with IIS Express is 7.9.0.0 where the full version of IIS comes with 7.0.0.0, 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


Comments

To add a comment, please login or register.

Related

Using a Lenovo P51 Laptop with an Airplane Power Supply
The Lenovo P51 Laptop comes with a huge 170 watt Power Supply. However, airplane power supplies provide a maximum of somewhere between 75-100 watts. If you plugin a power supply requiring more watts, the circuit breaker will short out and the power will stop flowing.
Turning Atlassian JIRA into a CRM
Here at Member.buzz, we use Atlassian JIRA to track our features, bugs, and incoming requests from users through our Support Site. So when it came to choosing a CRM, we wanted to find one that integrated nicely with the rest of our infrastructure.Our first thought was to try out some of the existing JIRA CRM plugins. Here are the ones we tried out:CRM for JIRAAtlas CRMKanoah CRMAlthough there were definitely some interesting features among these options, there was nothing substantial enough to make us want to choose a specific one. We wanted something simple, yet well-integrated into what we already had
Setup Point-to-Site VPN with Ubiquiti EdgeRouter
Learn how to setup a VPN with your Ubiquiti EdgeRouter.
C-Level Security: When your team uses military analogies, are they using the wrong narrative?
For years, I have bristled when people would use medieval military descriptions in an attempt to convey concepts within the Network Security business. Bastions, Firewalls, Moats, Drawbridges, Countermeasures; all of these descriptions give way to a more accurate and detailed explanation of what was really taking place.