关于使用Razor语法的MVC4项目的异常处理,我遵循了以下教程:http://www.devcurry.com/2012/06/aspnet-mvc-handling-exceptions-and-404.html
在遵循它之后,我仍然得到运行时错误,因此当我例如输入错误的url时,不会重定向到我的错误页面。当我这样做时,异常被记录下来,并且我通过了我在教程中添加的方法,但最后它转到了下面的页面:
http://[ipadress]:9880/Error?aspxerrorpath=/test
向我展示了:
Runtime Error
Description: An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated. 本教程和我的项目之间唯一的主要区别是我使用了一种额外的细分语言。
我为错误处理实现了以下代码。
在routeConfig文件中:
routes.MapRoute(
name: "FailWhale",
url: "{language}/FailWhale/{action}/{id}",
defaults: new { language = "en-US", controller="Error" ,action = "FailWhale", id = UrlParameter.Optional }
);在我的filterConfig中:
public class HandleAndLogErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
var exception = filterContext.Exception;
var httpException = exception as HttpException;
if (httpException != null) LogGateway.For(this).Fatal("Fatal Http exception occured --- " + httpException.Message);
else LogGateway.For(this).Fatal("Fatal exception occured --- " + exception.Message);
base.OnException(filterContext);
}
}我的web.config:
<customErrors mode="On" defaultRedirect="Error">
<error statusCode="404" redirect="en-US/FailWhale" />
</customErrors>我的错误控制器:
public ActionResult FailWhale()
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
LogGateway.For(this).Error("Fatal Http exception occured --- " + Response.StatusCode + ": " + Response.StatusDescription);
return View();
}我可能在这里监督什么?
发布于 2013-04-04 01:28:49
我已将运行该网站的PC链接到dyndns.org子域进行测试,并发现我的问题得到了正确处理。
https://stackoverflow.com/questions/14550911
复制相似问题