예제 #1
0
        private bool ExecuteUserController(HttpContextBase httpContext)
        {
            if (NoUserController)
            {
                return(false);
            }

            var model = new CoderrViewModel
            {
                ReportId           = _errorId,
                Exception          = _exception,
                HttpStatusCode     = HttpCode,
                HttpStatusCodeName = HttpCodeName
            };

            _routeData.DataTokens["OneTrueModel"] = model;
            _routeData.Values["action"]           = HttpCodeName;

            try
            {
                var controllerFactory = ControllerBuilder.Current.GetControllerFactory();
                var controller        = controllerFactory.CreateController(new RequestContext(httpContext, _routeData), "Error");
                controller.Execute(new RequestContext(httpContext, _routeData));
                return(true);
            }
            catch (HttpException controllerNotFoundException)
            {
                if (controllerNotFoundException.StackTrace.Contains("HandleUnknownAction"))
                {
                    try
                    {
                        var controllerFactory = ControllerBuilder.Current.GetControllerFactory();
                        var controller        = controllerFactory.CreateController(
                            new RequestContext(httpContext, _routeData), "Error");
                        _routeData.Values["Action"] = "Index";
                        controller.Execute(new RequestContext(httpContext, _routeData));
                        return(true);
                    }
                    catch
                    {
                    }
                }
                NoUserController = true;
                return(false);
            }
        }
 public ActionResult Index(CoderrViewModel model)
 {
     return(View("Error", model));
 }
 public ActionResult InternalServerError(CoderrViewModel model)
 {
     return(View(model));
 }
 public ActionResult NotFound(CoderrViewModel model)
 {
     return(View(model));
 }
예제 #5
0
        private bool ExecuteUserView(HttpContextBase httpContext)
        {
            if (NoUserViews)
            {
                return(false);
            }

            var controller     = new CoderrController();
            var requestContext = new RequestContext(httpContext, _routeData);

            var model = new CoderrViewModel
            {
                ReportId           = _errorId,
                Exception          = _exception,
                HttpStatusCode     = HttpCode,
                HttpStatusCodeName = HttpCodeName
            };

            var ctx = new ControllerContext(requestContext, controller);

            ctx.Controller.ViewData.Model = model;
            var viewName = GetViewName(ctx, string.Format("~/Views/Error/{0}.cshtml", HttpCodeName),
                                       "~/Views/Error/Error.cshtml",
                                       "~/Views/Error/General.cshtml",
                                       "~/Views/Shared/Error.cshtml");

            if (viewName == null)
            {
                NoUserViews = true;
                return(false);
            }

            var result = new ViewResult
            {
                ViewName   = viewName,
                MasterName = null,
                ViewData   = new ViewDataDictionary <CoderrViewModel>(model)
            };

            try
            {
                result.ExecuteResult(ctx);
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message.Contains("HandleErrorInfo"))
                {
                    requestContext.HttpContext.Response.Write(@"<html>
<head>
<title>Configuration error</title>
</head>
<body>
<h1>Configuration error</h1>
<p>The default ASP.NET MVC error view <code>Shared\Error.cshtml</code> uses <code>HandleErrorInfo</code> as a view model while codeRR expects <code>CoderrViewModel</code>.</p>
<p>You have three options:</p>
<ol>
<li>Change view model in it: <code>@model Coderr.Client.AspNet.Mvc5.CoderrViewModel</code></li>
<li>Remove the view <code>Shared\Errors.cshtml</code> to get codeRRs built in error pages.</li>
<li>Disable codeRRs error page handling, remove <code>Err.Configuration.DisplayErrorPages();</code> from global.asax.</li>
</ol>
<h1>Actual error</h1>
<pre>" + model.Exception + "</pre></body></html>");
                    requestContext.HttpContext.Response.ContentType = "text/html";
                    requestContext.HttpContext.Response.End();
                }
                Err.Report(ex, model);
            }
            catch (Exception ex)
            {
                Err.Report(ex, model);
            }

            return(true);
        }