Exemplo n.º 1
0
        /// <summary>
        /// Called when a request matches this controller, but no method with the specified action name is found in the controller.
        /// </summary>
        /// <param name="actionName">The name of the attempted action.</param>
        protected override void HandleUnknownAction(string actionName)
        {
            // Avoid IIS7 getting in the middle
            Response.TrySkipIisCustomErrors = true;

            IController errorsController = new Controllers.ErrorController();
            var errorRoute = new RouteData();
            errorRoute.Values.Add("controller", "error");
            errorRoute.Values.Add("action", "notfound");
            errorRoute.Values.Add("url", HttpContext.Request.Url.OriginalString);
            errorsController.Execute(new RequestContext(HttpContext, errorRoute));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called when a request matches this controller, but no method with the specified action name is found in the controller.
        /// </summary>
        /// <param name="actionName">The name of the attempted action.</param>
        protected override void HandleUnknownAction(string actionName)
        {
            // Avoid IIS7 getting in the middle
            Response.TrySkipIisCustomErrors = true;

            IController errorsController = new Controllers.ErrorController();
            var         errorRoute       = new RouteData();

            errorRoute.Values.Add("controller", "error");
            errorRoute.Values.Add("action", "notfound");
            errorRoute.Values.Add("url", HttpContext.Request.Url.OriginalString);
            errorsController.Execute(new RequestContext(HttpContext, errorRoute));
        }
            private void RedirectToErrorAction(HttpContext context, string actionName)
            {
                context.Server.ClearError();
                context.Response.TrySkipIisCustomErrors = true;
                context.Response.Clear();
                RouteData routeData = new RouteData();

                routeData.Values.Add("controller", "error");
                routeData.Values.Add("action", actionName);
                IController errorController    = new Controllers.ErrorController();
                var         httpContextWrapper = new HttpContextWrapper(context);
                var         requestContext     = new RequestContext(httpContextWrapper, routeData);

                errorController.Execute(requestContext);
            }
    public override void OnException(System.Web.Mvc.ExceptionContext filterContext)
    {
        filterContext.ExceptionHandled = true;

        var routeData = new RouteData();

        routeData.Values["controller"] = "Error";
        routeData.Values["action"]     = "Error";
        routeData.DataTokens["area"]   = "app";

        IController errorsController = new Controllers.ErrorController();
        var         rc = new RequestContext(new HttpContextWrapper(HttpContext.Current), routeData);

        errorsController.Execute(rc);
        base.OnException(filterContext);
    }
Exemplo n.º 5
0
        void Application_Error(object sender, EventArgs e)
        {
            var exception = context.Server.GetLastError();

            TryLogException(exception);
            var httpException = exception as HttpException;

            context.Response.Clear();
            context.Server.ClearError();
            var routeData = new RouteData();

            routeData.Values["controller"] = "Error";
            routeData.Values["action"]     = "General";
            routeData.Values["exception"]  = exception;
            context.Response.StatusCode    = 500;

            if (httpException != null)
            {
                context.Response.StatusCode = httpException.GetHttpCode();
                switch (context.Response.StatusCode)
                {
                case 401:
                    routeData.Values["action"] = "Http401";
                    break;

                case 403:
                    routeData.Values["action"] = "Http403";
                    break;

                case 404:
                    routeData.Values["action"] = "Http404";
                    break;
                }
            }

            IController errorsController = new Controllers.ErrorController();
            var         requestedContext = new RequestContext(new HttpContextWrapper(context.Context), routeData);

            errorsController.Execute(requestedContext);
        }