测试的最佳方式,如果一个网站是从C#应用程序了活着 [英] Best way to test if a website is alive from a C# applicaiton

查看:143
本文介绍了测试的最佳方式,如果一个网站是从C#应用程序了活着的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找测试如果一个网站是从C#应用程序还活着的最好方法。

背景

我的应用程序包含一个的的WinForms UI 的,后端的 WCF服务的和一个的网站的发布内容到用户界面和其他消费者。以prevent当UI启动并失败,因为缺少WCF服务或网站当我增加了一个应用程序启动时检查,以确保所有的一切都还活着才能正常工作。这种情况

应用程序正在writen在C#中的.Net 3.5,Visual Studio 2008的SP1

目前的解决方案

目前,我提出一个web请求测试页在网站上,将inturn测试Web网站,然后显示一个结果。

 的WebRequest请求= WebRequest.Create(HTTP://localhost/myContentSite/test.aspx);
WebResponse的响应= request.GetResponse();

我假设,如果没有这个通话过程中thown异常就万事大吉了和用户界面可以启动。



这是最简单的/正确的方式或者是有一些其他的shneaky电话,我在C#中做不知道或更好的方式来做到这一点。


解决方案

  HttpWebResponse响应=(HttpWebResponse)request.GetResponse();
如果(响应== NULL || response.Status code!=的HTTPStatus code.OK)

I am looking for the best way to test if a website is alive from a C# application.

Background
My application consists of a Winforms UI, a backend WCF service and a website to publish content to the UI and other consumers. To prevent the situation where the UI starts up and fails to work properly because of a missing WCF service or website being down I have added an app startup check to ensure that all everything is alive.

The application is being writen in C#, .Net 3.5, Visual Studio 2008 SP1

Current Solution
Currently I am making a web request to a test page on the website that will inturn test the web site and then display a result.

WebRequest request = WebRequest.Create("http://localhost/myContentSite/test.aspx");
WebResponse response = request.GetResponse();

I am assuming that if there are no exceptions thown during this call then all is well and the UI can start.

Question
Is this the simplest/ right way or is there some other shneaky call that I do no know about in C# or a better way to do it.

解决方案

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response == null || response.StatusCode != HttpStatusCode.OK)

这篇关于测试的最佳方式,如果一个网站是从C#应用程序了活着的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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