是否可以以编程方式启动/停止 IIS 中的应用程序池或网站?

发布于 2024-07-27 04:22:17 字数 187 浏览 2 评论 0原文

我正在尝试找到一种方法来从同一服务器上的 Web 界面内停止、启动、重新启动/回收网站和应用程序池。 理想情况下,这将是我可以使用 .NET 完成的事情,而无需执行 shell 命令。

(我看到有人提出了其他相关问题,但除非有必要,否则我不想从命令行执行此操作)。

我需要能够为 IIS6 和 IIS7 执行此操作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬心 2024-08-03 04:22:17

您正在寻找 Microsoft.Web.Administration.ServerManager 类。 您可以在此处找到一些入门代码: http://learn.iis.net/page .aspx/226/microsoftwebadministration/

您可以进一步探索该代码来执行您想要的操作。 我相信整个 appcmd 都是在此框架之上编写的。

该框架不适用于 IIS6 及以下版本。 你需要IIS7。 对于 II6,您可以使用 Mehmet Aras 建议的 WMI 方法。 不幸的是,你需要这两个库; 或者也许有一些代码可以抽象这些库。

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.

夏末 2024-08-03 04:22:17

您可以使用 WMI(Windows 管理规范)。 查看 msdn 上的使用 WMI 配置 IIS。您可以还可以通过 C# 代码访问 WMI 提供程序并与它们交互,包括 IIS。 System.Management 命名空间是一个起点。

我要提醒您的一件事是查明 .NET 中的 WMI 代码是否需要完全信任,因为您希望能够在默认情况下不以完全信任方式运行的 .NET Web 应用程序中执行此操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文