我想处理应用程序级别的任何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