views:

764

answers:

2

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 quesitons have been asked but I don't want to do this from the command line unless that's necessary.)

Edit: I need to be able to do this in IIS6 and 7

+2  A: 

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

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

EDIT: I forgot to mention that this framework will not work for IIS6 and below. You need IIS7.

EDIT2: For II6 you could use the WMI approach as suggested by Mehmet Aras. It is unfortunate, but you need these two libraries; or may be there is some code out there that abstracts these libraries.

Charles Prakash Dasari
A: 

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.

Mehmet Aras