首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行时错误,即使有错误处理

运行时错误,即使有错误处理
EN

Stack Overflow用户
提问于 2013-01-28 02:52:19
回答 1查看 2.5K关注 0票数 0

关于使用Razor语法的MVC4项目的异常处理,我遵循了以下教程:http://www.devcurry.com/2012/06/aspnet-mvc-handling-exceptions-and-404.html

在遵循它之后,我仍然得到运行时错误,因此当我例如输入错误的url时,不会重定向到我的错误页面。当我这样做时,异常被记录下来,并且我通过了我在教程中添加的方法,但最后它转到了下面的页面:

http://[ipadress]:9880/Error?aspxerrorpath=/test

向我展示了:

代码语言:javascript
复制
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文件中:

代码语言:javascript
复制
        routes.MapRoute(
            name: "FailWhale",
            url: "{language}/FailWhale/{action}/{id}",
            defaults: new { language = "en-US", controller="Error" ,action = "FailWhale", id = UrlParameter.Optional }
        );

在我的filterConfig中:

代码语言:javascript
复制
    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:

代码语言:javascript
复制
<customErrors mode="On" defaultRedirect="Error">
  <error statusCode="404" redirect="en-US/FailWhale" />
</customErrors>

我的错误控制器:

代码语言:javascript
复制
    public ActionResult FailWhale()
    {
        Response.StatusCode = 404;
        Response.TrySkipIisCustomErrors = true;

        LogGateway.For(this).Error("Fatal Http exception occured --- " + Response.StatusCode + ": " + Response.StatusDescription);

        return View();
    }

我可能在这里监督什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-04 01:28:49

我已将运行该网站的PC链接到dyndns.org子域进行测试,并发现我的问题得到了正确处理。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14550911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档