如何检查Web服务器是否启动? (C#) [英] How to check if Web server is up? (C#)

查看:634
本文介绍了如何检查Web服务器是否启动? (C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个监视应用程序,以连续监视系统的各个方面.我希望使用Ping()函数来确定服务器是否已启动,但 MSDN文档本身说,这不是最好的方法:

I am building a monitoring application to continuously monitor all aspects of my system. I was hoping to use the Ping() function to determine if the server is up but the MSDN documentation itself says that it is not the best way:

成功的Ping仅表示 远程主机可以在 网络;更高层次的存在 服务上的服务(例如Web服务器) 不能保证远程主机.

A successful Ping indicates only that the remote host can be reached on the network; the presence of higher level services (such as a Web server) on the remote host is not guaranteed.

还有其他更好的方法吗?

Are there any other ways to do this better?

推荐答案

您需要确定要测试的页面/URL,要么是已经存在的页面,要么是为检查目的而创建的页面/URL.服务器的可用性.

You'll need to settle on one page/url that you wish to test, either one that's already there or one that you create for the specific purpose of checking the servers availability.

每隔[时间段],您都可以对此URL进行请求,并检查响应以确定是否包含预期值,例如,如果您请求mysite.com/default.aspx,则显示页面的内容.最好的办法是将一个url/page/web服务调用专用于"ping",因为如果您检查的任意页面的内容在不知情的情况下发生了更改,它就可以确保它不会被破坏.

Once every [period of time] you can make a request to this url and examine the response to determine if it contain the expected value(s), such as the content of a page if you requested mysite.com/default.aspx. The best thing to do is to dedicate one url/page/web service call to the "ping" as it ensures that it doesn't get broken if the content of the arbitary page you're checking is changed without you being made aware.

我建议反对要做的一件事是让此ping方法测试一切,包括您的数据库连接性,第三方网络服务可用性,磁盘空间等. ..如果要执行此操作,则可以调用多种方法,以便一目了然地准确了解问题的根源.

One thing I do recommend against doing is having this one ping method test everything, including your database connectivity, 3rd party web service availability, disk space, etc,... If you want to do this, have multiple methods that you can call so you can see at a glance precisely what's causing the problem.

这篇关于如何检查Web服务器是否启动? (C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆