Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interacting with IIS via C#

Tags:

c#

asp.net

iis

I have a C# program used to build and deploy a suite of websites.

I would like to programatically interact with IIS so that it changes where the virtual directory for a test system points to based the result of the build.

Is this possible or just crazy talk?

like image 484
AJM Avatar asked Mar 29 '11 13:03

AJM


3 Answers

Yes it is possible through WMI. Windows Management Instrumentation is basically an API around windows. You can programmaticly do many things with it.

IIS 6 and lower you need WMI, IIS 7 and greater is a lot simpler as you just use the Microsoft.Web.Administration assembly.

WMI: http://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx

Microsoft.Web.Administration: http://msdn.microsoft.com/en-us/library/ms613523%28v=VS.90%29.aspx

like image 182
Chris Kooken Avatar answered Nov 20 '22 14:11

Chris Kooken


Use Microsoft.Web.Administration DLL and you can automate IIS 7 and above.

Have a look here.

like image 4
Aliostad Avatar answered Nov 20 '22 13:11

Aliostad


Which version of IIS? If using 5.1 or 6, you'll have to use com objects to get there. If using 7, you have the option of new classes in .net.

For 5.1 and 6, I tend to use ADSI, rather than WMI, because I've seen a lot of systems where WMI is flaky or not installed correctly. Unsure how this happens, but I've never run across a problem using the ADSI objects. Note: You can actually still use these under IIS 7, but you need to enable the IIS 6 Management Compatibility option, under add/remove windows features.

For more information on IIS7-based objects, check out: Creating Virtual directory in IIS with c#

like image 1
Lynn Crumbling Avatar answered Nov 20 '22 13:11

Lynn Crumbling