/// <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.ErrorsController(); var errorRoute = new RouteData(); errorRoute.Values.Add("controller", "errors"); errorRoute.Values.Add("action", "notfound"); errorRoute.Values.Add("url", HttpContext.Request.Url.OriginalString); errorsController.Execute(new RequestContext(HttpContext, errorRoute)); }
/// <summary> /// Handles the Error event of the Application control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Application_Error(object sender, EventArgs e) { var exception = Server.GetLastError(); var httpException = exception as HttpException; Server.ClearError(); var routeData = new RouteData(); routeData.Values["controller"] = "Errors"; routeData.Values["action"] = "General"; routeData.Values["exception"] = exception; if (httpException != null) { var statusCode = httpException.GetHttpCode(); switch (statusCode) { case 401: routeData.Values["action"] = "NotAuthorized"; break; case 403: routeData.Values["action"] = "Forbidden"; break; case 404: routeData.Values["action"] = "NotFound"; break; } } // Avoid IIS7 getting in the middle Response.TrySkipIisCustomErrors = true; IController errorsController = new Controllers.ErrorsController(); HttpContextWrapper wrapper = new HttpContextWrapper(Context); var rc = new RequestContext(wrapper, routeData); errorsController.Execute(rc); }