简体   繁体   English

如何ping在iis中部署的网站/ ip

[英]How to ping a website / ip that is deployed in iis

I need to make a website that is designed to monitor / check the connectivity of our internal applications that is deployed on iis, Its like a list of links to our internal websites that we developed. 我需要建立一个网站,旨在监控/检查部署在iis上的内部应用程序的连接性,它就像我们开发的内部网站的链接列表。 The question is, how would I be able to check if a website is up and running? 问题是,我如何能够检查网站是否正常运行? and how would I check if a website is down? 以及如何检查网站是否已关闭? I will simply display the links of our system and color it based on their status, green for up, and red if its down or has errors.. hoping for your advice. 我将简单地显示我们系统的链接,并根据它们的状态对其进行着色,绿色为up,如果是向下或有错误则为红色..希望得到您的建议。 sample codes would be appreciated. 样品代码将不胜感激。

只需从该服务器加载任何内容,如果它加载您的站点已启动并正在运行,如果它没有加载,则只生成错误或显示红色

The simplest way to do this is to have a windows service or scheduled task running which performs WebRequests against the list of websites and checking the status codes. 最简单的方法是运行Windows服务或计划任务,根据网站列表执行WebRequests并检查状态代码。

If a status code of 200 is returned, show green. 如果返回状态代码200,则显示绿色。 Anything else (4xx, 5xx, timeout), show red. 其他任何东西(4xx,5xx,超时),显示红色。 Have the service store the results in a database and have the 'red-green' page read from that database. 让服务将结果存储在数据库中,并从该数据库中读取“红绿”页面。

That would be a generic, one-size-fits-all solution. 这将是一种通用的,一刀切的解决方案。 It may not work for all sites, as some sites could have basic authentication, in which case your monitor will incorrectly record that the site is down. 它可能不适用于所有站点,因为某些站点可能具有基本身份验证,在这种情况下,您的监视器将错误地记录该站点已关闭。 So you would need to store metadata against the sites and perform basic authentication (or any other business logic) to determine whether it's up or down. 因此,您需要针对站点存储元数据并执行基本身份验证(或任何其他业务逻辑)以确定它是向上还是向下。

If you have access to the websites you want to monitor then I would have thought the easiest way is to put a status page on the websites you want to monitor designed to be polled by your service. 如果您可以访问要监控的网站,那么我认为最简单的方法是在您要监控的网站上放置一个状态页,以便您的服务进行轮询。 This way if the website is up you can get more advanced status information from it by reading the page content. 这样,如果网站启动,您可以通过阅读页面内容从中获取更高级的状态信息。

If you just want to check the http status then just access any page on the website (preferably a small one!) and check the response status code. 如果您只想检查http状态,那么只需访问网站上的任何页面(最好是一个小页面!)并检查响应状态代码。

Something like 就像是

                // prepare the web page we will be asking for
                HttpWebRequest request = (HttpWebRequest)
                    WebRequest.Create(Url);
                //if (AuthRequired())
                //    request.Credentials = new NetworkCredential(Username, Password);
                // execute the request
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

then you can read the response.StatusCode 那么你可以阅读response.StatusCode

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

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