您的錯誤將通過Global.asax.cs文件(您可能需要創建)的Application_Error方法。我用這個事實來捕獲錯誤,並將其記錄到數據庫:
void Application_Error(object sender, EventArgs e)
{
try
{
SqlConnection errConnection = new SqlConnection("Your connection string");
// After setting up a command object, I call a stored procedure to save information about
// the crash. I pass two primary arguments. The first is the URL:
errCommand.Parameters.Add("@URL", SqlDbType.VarChar).Value = Request.Url.ToString();
// The second is the error information.
errCommand.Parameters.Add("@EI", SqlDbType.Text).Value = Server.GetLastError().ToString();
// I pass some other information from my session as well...
// After setting up an output parameter called ErrorID, I call the command...
errCommand.ExecuteNonQuery();
// Now Error ID is stored in the session.
Session["ErrorID"] = (int)ErrorID.Value;
}
catch { } // I do NOT want the error handling call to throw an error.
}
現在,這樣當發生特定頁面獲得控制權的錯誤,你應該已經建立了你的web.config文件。在此頁面中,您將檢查會話中的錯誤ID並將其顯示給用戶。在輸出中,我要求用戶寫下錯誤,如果他們想給我們打電話瞭解更多信息。如果我們收到請求,我可以進入數據庫並獲得錯誤的完整跟蹤。
相關:http://stackoverflow.com/questions/10053342/open-source-multi-platform-browser-based-screen-capture-extension – cregox 2015-03-31 22:13:45