且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查Web服务器是否启动? (C#)

更新时间:2023-11-27 18:53:40

您需要确定要测试的页面/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.