我們有一個內聯網網頁,用於顯示信息在我們網站周圍的顯示器上工作。該網頁每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