Is it possible to start / stop an application pool or website in IIS programatically?

牧云@^-^@ 提交于 2019-12-03 11:22:08

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1148511/is-it-possible-to-start-stop-an-application-pool-or-website-in-iis-programatic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!