asp.net-mvc-3 – 找不到视图’错误’或其主人

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – 找不到视图’错误’或其主人前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我花了很多时间试图找出一个解决方法,这无法使用,所以我想我会看到,如果有人在这里有一个想法。

我使用Elmah in my ASP.NET MVC3 application.我使用完全相同的代码从上一个链接中接受的答案。

我也有这个代码在我的Global.asax显示错误页面与正确的HTTP响应:

/// <summary>
    /// The customErrors functionality provided by ASP.NET results in HTTP 302 redirects occurring which doesn't accurately reflect what the real HTTP code of the response was.
    /// This method can be used to handle specific HTTP codes without an intermediate redirect.
    /// </summary>
    protected void Application_Error() {
        var exception = Server.GetLastError();
        var httpException = exception as HttpException;
        Response.Clear();
        Server.ClearError();
        var routeData = new RouteData();
        routeData.Values["controller"] = "Error";
        routeData.Values["action"] = "Error500";
        Response.StatusCode = 500;

        if (httpException != null) {
            Response.StatusCode = httpException.GetHttpCode();
            Response.TrySkipIisCustomErrors = true;
            switch (Response.StatusCode) {
                case 403:
                    routeData.Values["action"] = "Error403";
                    break;
                case 404:
                    routeData.Values["action"] = "Error404";
                    routeData.Values["message"] = httpException.Message;
                    break;
                case 500:
                    routeData.Values["action"] = "Error500";
                    break;
            }
        }

        IController errorsController = new ErrorController();
        var rc = new RequestContext(new HttpContextWrapper(Context),routeData);
        errorsController.Execute(rc);
    }

当我不在我的(本地)开发机器(最初让我认为它是customErrors相关)时,问题发生。当抛出异常时,Elmah处理错误并正确记录它。我也得到正确的错误页面。但是,在结束正确的错误页面之前,我可以看到另一个中间异常被记录:

The view 'Error' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/Articles/Error.aspx ~/Views/Articles/Error.ascx ~/Views/Shared/Error.aspx ~/Views/Shared/Error.ascx ~/Views/Articles/Error.cshtml ~/Views/Articles/Error.vbhtml ~/Views/Shared/Error.cshtml ~/Views/Shared/Error.vbhtml

ASP.NET试图加载默认错误页面,即使我试图处理它。有没有人有任何想法如何防止这一点?

解决方法

不要调用base.OnException(context);方法在您的自定义错误处理程序从HandleErrorAttribute派生。您不再需要它,因为您在Application_Error中实现了自定义错误处理。

猜你在找的asp.Net相关文章