我已经按照以下教程使用razor语法处理我的MVC4项目的异常处理: http://www.devcurry.com/2012/06/aspnet-mvc-handling-exceptions-and-404.html
在关注它之后,我仍然遇到运行时错误,因此当我输入一个不正确的URL时,不会发生重定向到我的错误页面。 当我这样做时,会记录异常,并且我会通过我在教程中添加的方法,但最后会转到以下页面:
的http:// [ipadress]:9880 /错误aspxerrorpath = /测试
并告诉我:
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();
}
我可能在这里监督一些事情?
答案 0 :(得分:0)
我已将运行该网站的PC与dyndns.org子域链接以进行测试,并发现我的问题正在得到正确处理。