Question

I'm trying to find a way to stop, start, restart/recycle websites and application pools from within a web interface on the same server. Ideally this would be something I could do with .NET without having to execute shell commands.

(I see other related questions have been asked but I don't want to do this from the command line unless that's necessary).

I need to be able to do this for both IIS6 and IIS7.

Was it helpful?

Solution

You are looking for the Microsoft.Web.Administration.ServerManager class. You can find some starter code here: http://learn.iis.net/page.aspx/226/microsoftwebadministration/.

You can explore that code further to do what you want. I believe the whole appcmd is written on top of this framework.

This framework will not work for IIS6 and below. You need IIS7. For II6 you could use the WMI approach as suggested by Mehmet Aras. It is unfortunate, but you need these two libraries; or maybe there is some code out there that abstracts these libraries.

OTHER TIPS

You can use WMI (Windows Management Instrumentation). Take a look at Using WMI to Configure IIS on msdn.You can also access WMI providers and interact with them including IIS from C# code. System.Management namespace is a place to start.

One thing I would caution you is to find out if the WMI code in .NET requires full-trust or not since you want to be able to do this from within a .NET web application which does not run in full-trust by default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top