【问题标题】:Redirect in Application_Error not working in IE & EdgeApplication_Error 中的重定向在 IE 和 Edge 中不起作用
【发布时间】:2016-01-12 18:41:05
【问题描述】:

当出现未处理的错误时,我已经全局编写了一些代码来重定向到自定义 MVC 操作。

此代码在 Chrome 中运行良好,但在 IE 和 Edge 中失败。 IE & Edge 正在显示它们的默认错误页面。

这是我 global.asax 的 Application_Error

    protected void Application_Error(object sender, EventArgs e)
    {
        var lastException = Server.GetLastError();

        var wrappedContext = new HttpContextWrapper(Context);
        wrappedContext.Response.StatusCode = (lastException as HttpException)?.GetHttpCode() ?? 500;
        wrappedContext.Response.Clear();
        wrappedContext.Response.TrySkipIisCustomErrors = true;
        wrappedContext.Server.ClearError();

        var routeData = new RouteData();
        routeData.Values.Add("area", "");
        routeData.Values.Add("controller", "Error");
        routeData.Values.Add("action", "Index");
        routeData.Values.Add("httpResponseCode", Context.Response.StatusCode);

        IController errorController = DependencyResolver.Current.GetService<ErrorController>();
            errorController.Execute(new RequestContext(wrappedContext, routeData));
    }

【问题讨论】:

    标签: asp.net-mvc internet-explorer asp.net-mvc-5 global-asax


    【解决方案1】:

    上面的代码运行良好...问题出在视图中...

    代码如下:

    @{
        ViewBag.Title = "Oops, something went wrong...";
        Layout = null;
    }
    
    TODO: Nice error page
    

    IE & Edge 有以下限制显示自定义错误页面 (Table source):

    所以添加一些超过 512 字节的虚拟文本使其工作......

    不知道为什么 MS 在 IE 和 Edge 中这样做?!?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 2018-04-18
      • 2018-11-19
      • 2017-12-10
      • 1970-01-01
      相关资源
      最近更新 更多