繁体   English   中英

如何使用 C# 检查我的 IIS 是否还活着?

[英]How can I check if my IIS is alive using C#?

如何使用 C# 检查我的 IIS 是否还活着?

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

使用 WebRequest 尝试打开页面怎么样? 如果它没有返回任何东西给你,那么也许使用进程 class 来调用 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 到 localhost。 如果您收到响应,则意味着您的 IIS 已启动,如果没有,则已关闭。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM