/// <summary> /// Wrap the current request context around an error controller instance. /// </summary> public static ErrorController Instance(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } ErrorController controller = new ErrorController(); RouteData data; MvcHandler handler = httpContext.Handler as MvcHandler; if (handler == null || handler.RequestContext == null || handler.RequestContext.RouteData == null) { data = new RouteData(); data.Values.Add(Constants.RouteDataController, Constants.RouteDataControllerNotFound); data.Values.Add(Constants.RouteDataAction, Constants.RouteDataActionNotFound); } else { data = handler.RequestContext.RouteData; } controller.ControllerContext = new ControllerContext(httpContext, data, controller); return controller; }
/// <summary> /// Wrap the current request context around an error controller instance. /// </summary> public static ErrorController Instance(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } ErrorController controller = new ErrorController(); RouteData data; MvcHandler handler = httpContext.Handler as MvcHandler; if (handler == null || handler.RequestContext == null || handler.RequestContext.RouteData == null) { data = new RouteData(); data.Values.Add(Constants.RouteDataController, Constants.RouteDataControllerNotFound); data.Values.Add(Constants.RouteDataAction, Constants.RouteDataActionNotFound); } else { data = handler.RequestContext.RouteData; } controller.ControllerContext = new ControllerContext(httpContext, data, controller); return(controller); }
private void WriteGracefulResponse(Exception exception, ErrorController controller) { try { // write an HTML response from an embedded resource in the assembly. WriteHtmlResponse(exception, controller); } catch (Exception exceptionRenderingHtml) // we seem to be having a very rough day, lets just call it a day. { Exception concatenated = helper.ConcatExceptions(exception, exceptionRenderingHtml); WritePlainTextResponse(controller.Response, concatenated); // write a plain text response. } }