我想处理应用程序级别的任何 Oracle Db 异常。因此在 Global.asax 的 Application_Error 函数中编写了以下代码
代码似乎更具体,但我想为任何类型的 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 类吗?