[英]What is the equivalent of an IISReset if I want to use Microsoft.Web.Administration
It would appear that there is more involved than just iterating the ApplicationPools and calling Recycle() on them. 看起来涉及的不仅仅是迭代ApplicationPools并在它们上调用Recycle()。 How do I most closely mimic an IISReset programatically (from .Net) without resorting to shell invocation? 如何在不诉诸shell调用的情况下以编程方式(来自.Net)最接近地模仿IISReset?
And I suppose most importantly: Are there things that IISReset does that can't be accomplished via the tools available in Microsoft.Web.Administration namespace? 我认为最重要的是:IISReset是否有通过Microsoft.Web.Administration命名空间中提供的工具无法实现的功能?
You can use System.ServiceProcess.ServiceController (got the idea from this answer ), by starting or stopping the following services: 您可以通过启动或停止以下服务来使用System.ServiceProcess.ServiceController(通过此答案获得了想法):
-Windows Process Activation Service (WAS) -Windows进程激活服务(WAS)
-World Wide Web Publishing Service (W3SVC) - 万维网发布服务(W3SVC)
Here's some code that'll do the job: 这里有一些代码可以完成这项工作:
//stop iis (like running "IISReset /Stop")
ResetService("WAS", false);
ResetService("W3SVC", false);
//start iis (like running "IISReset /Start")
ResetService("WAS", true);
ResetService("W3SVC", true);
private static void ResetService(string name, bool start)
{
using (var service = new System.ServiceProcess.ServiceController(name))
{
if (start && service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
}
else if (!start && service.Status == ServiceControllerStatus.Running)
{
service.Stop();
}
}
}
As for other IISReset commands, you could code in a timeout easily enough. 对于其他IISReset命令,您可以足够轻松地编写超时代码。 And to reboot the computer, check out this answer . 要重新启动计算机,请查看此答案 。 Let me know if you need any more details. 如果您需要更多详细信息,请与我们联系。
But if that's not enough of a party for ye, you can always execute power shell scripts in c#, using this technique (pretty baller, if you just need to get 'er done). 但是,如果这对你们来说还不够,那么你总是可以使用这种技术在c#中执行power shell脚本(如果你只是需要完成,那就太漂亮了)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.