简体   繁体   中英

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. 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. 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.

If a status code of 200 is returned, show green. Anything else (4xx, 5xx, timeout), show red. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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