我想處理應用程序級別的任何Oracle Db異常。因此在Global.asax的Application_Error函數中編寫了下面的一段代碼如何檢查異常是否是Oracle異常?
代碼似乎更具體,但我想爲任何類型的Oracle異常。
protected void Application_Error(object sender, EventArgs e)
{
var isOracleException = false;
//Get the error details.
Exception lastException = Server.GetLastError();
if (lastException != null)
{
if (lastException.Message.StartsWith("ORA"))
{
isOracleException = true;
}
}
HttpContext httpContext = (sender as MvcApplication).Context;
httpContext.ClearError();
httpContext.Response.Clear();
httpContext.Response.TrySkipIisCustomErrors = true;
RouteData routeData = new RouteData();
if (isOracleException)
{
routeData.Values["controller"] = "HandleError";
routeData.Values["action"] = "Error";
IController errorController = new HandleErrorController();
var requestContext = new RequestContext(new HttpContextWrapper(httpContext), routeData);
errorController.Execute(requestContext);
}
}
我們可以在Global.asax文件中訪問OracleException類嗎?
但如何?我的意思是我想寫它的任何Oracle錯誤.. – SantyEssac