我们有一个内联网网页,用于显示信息在我们网站周围的显示器上工作。该网页每15秒自动刷新一次。http状态码500 /网页停止刷新
所有这一切工作的寻找,直到数据库服务器有一个问题,网页,不再获得一个连接,我们得到一个错误,回到正常的HTTP 500错误。
我对这个解决方案是写检查网页的HTTP状态C#应用程序,如果一个HTTP 500被发现关闭浏览器,然后重新打开它,并显示该网页。 此应用程序正在使用定时器事件设置为30秒。
我遇到的问题是我的C#应用程序并不总是拿起500错误,或可能导致网页停止更新任何其他错误。
下面是我写的尝试和检查错误(S)
public static void Check_Process()
{
Console.Write("checking started at {0}" + Environment.NewLine, DateTime.Now);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(txt_url);
response = (HttpWebResponse)request.GetResponse();
// Read the error stream first and then wait.
string error = someProcess.StandardError.ReadToEnd();
Console.Write(error);
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
response = (HttpWebResponse)e.Response;
if ((int)response.StatusCode == 500)
{
Console.Write((int)response.StatusCode + " error found at {0}" + Environment.NewLine, DateTime.Now);
Close_webpage();
Start_webpage();
}
else if (response.StatusCode != HttpStatusCode.OK)
{
Console.Write((int)response.StatusCode + " error found at {0}" + Environment.NewLine, DateTime.Now);
Close_webpage();
Start_webpage();
}
}
}
}
的网页目前使用
public static void Start_webpage()
{
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.FileName = "IExplore.exe";
startInfo.Arguments = txt_url;
someProcess = Process.Start(startInfo);
}
希望有人能指出在应用程序中加载代码在那里我错了,或者更好的方式,因为目前我们不得不手动刷新/重新加载网页。
除了修复网络应用程序,所以它不是500? – GalacticCowboy 2013-04-30 02:05:59
if(e.Status!= WebExceptionStatus.ProtocolError) - 应用程序没有抛出异常,因此当e.Status不是一个值时,您可以忽略它。该应用正在尝试传达某些信息,请勿放弃该线索。 – MatthewMartin 2013-04-30 02:19:12
如果这是服务器上的错误,为什么要重新启动浏览器帮助? – 2013-04-30 02:25:22