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

编程入门 行业动态 更新时间:2024-10-06 09:22:24
本文介绍了如何检查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/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/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#)

本文发布于:2023-11-23 21:52:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622951.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!