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?
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
Use Microsoft.Web.Administration
DLL and you can automate IIS 7 and above.
Have a look here.
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#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With