如何使用C#检查我的IIS是否处于活动状态?

如何使用C#检查我的IIS是否处于活动状态?,c#,winforms,C#,Winforms,如何使用C#检查我的IIS是否处于活动状态 如果服务器关闭-如何进行iisreset?如何使用WebRequest尝试打开页面?如果它没有向您返回任何信息,那么可以使用Process类调用iisreset // Initialise the WebRequest. WebRequest webRequest = WebRequest.Create("[your URI here]"); // Return the response. WebResponse webResponse = webR

如何使用C#检查我的IIS是否处于活动状态


如果服务器关闭-如何进行iisreset?

如何使用WebRequest尝试打开页面?如果它没有向您返回任何信息,那么可以使用Process类调用iisreset

// Initialise the WebRequest.
WebRequest webRequest = WebRequest.Create("[your URI here]");
// Return the response. 
WebResponse webResponse = webRequest.GetResponse();
// Close the response to free resources.
webResponse.Close();

if (webResponse.ContentLength > 0) // May have to catch an exception here instead
{
    Process.Start("iisreset.exe", "/reset"); // Or whatever arg you want

}

它需要细致入微,但这是您所要求的内容的大致轮廓…

使用WebRequest尝试打开页面如何?如果它没有向您返回任何信息,那么可以使用Process类调用iisreset

// Initialise the WebRequest.
WebRequest webRequest = WebRequest.Create("[your URI here]");
// Return the response. 
WebResponse webResponse = webRequest.GetResponse();
// Close the response to free resources.
webResponse.Close();

if (webResponse.ContentLength > 0) // May have to catch an exception here instead
{
    Process.Start("iisreset.exe", "/reset"); // Or whatever arg you want

}

它需要改进,但这是您所要求的内容的大致轮廓…

您可以创建一个新的对localhost的WebRequest。如果您得到响应,这意味着您的IIS已启动,如果未启动,则已关闭


要重置它,请创建一个新进程并将iisreset作为参数传递。

您可以创建一个新的WebRequest到localhost。如果您得到响应,这意味着您的IIS已启动,如果未启动,则已关闭


要重置它,请创建一个新进程并将iisreset作为参数传递。

最好通过服务器的外部IP执行请求,甚至可以通过外部代理。最好通过服务器的外部IP执行请求,甚至可以通过外部代理执行请求。