开发者

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

How can开发者_运维知识库 I check if my IIS is alive using C#?

If the server is down - how to do iisreset ?


How about using WebRequest to try opening a page? If it doesn't return anything to you then perhaps use the Process class to call 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

}

It needs finessing but this is the broad outline of what you asked for...


You can create a new WebRequest to localhost. If you get a response, that means your IIS is up, if not, it's down.

To reset it, create a new Process and pass iisreset as an argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜