我的网站是否已关闭,无法正常运行或有错误?

Amr*_*rhy 1 .net c# vb.net asp.net web

我想创建一个小的Windows应用程序将自动每个时间段到我的网站,并检查它是否运行正常,如果它发现它,无法正常工作或有错误"示例:404,网络错误,连接到数据库失败"它将在我的屏幕上显示一条消息.

我怎么知道在程序上使用任何.NET语言都有错误?

Dan*_*ant 7

这很容易做到WebClient.它看起来像这样:

    WebClient client = new WebClient();
    try
    {
        string response =
            client.DownloadString("http://www.example.com/tester.cgi");

        // We at least got the file back from the server

        // You could optionally look at the contents of the file
        // for additional error indicators      
        if (response.Contains("ERROR: Something"))
        {
            // Handle
        }
    }
    catch (WebException ex)
    {
        // We couldn't get the file.
        // ... handle, depending on the ex
        //
        // For example, by looking at ex.Status:
        switch (ex.Status)
        {
            case WebExceptionStatus.NameResolutionFailure:
                // ...
            break;
            // ...
        }
    }
Run Code Online (Sandbox Code Playgroud)

你可以挂钩,达到某TimerTick事件或东西定期进行检查.


Joh*_*nFx 5

何必?您可以从像RedAlert这样的提供商那里获得更好的廉价解决方案

关于这个的好处是:

1)它从防火墙外部测试您的站点,因此它可以检测到更多种类的问题.

2)这是一个公正的第三方,因此如果您需要SLA,您可以证明正常运行时间.

3)对于小额赠品,您可以尝试并诊断问题.

4)当出现问题时,它可以给您发电子邮件或发送电子邮件.

5)您无需委托新服务器.

Geez,我听起来像是这些人的广告,但我保证我不会为他们工作或获得回扣.我对服务器的服务感到满意.

顺便说一句:我检查了价格,每个网站每月约20美元.因此,您可以花费更少的时间来支付一年的服务费用,而不是自己构建它.