private void HandleError(string action) { // This method causes the Errors controller to handle the request // It creates the controller, then executes the desired action method // With some more code, it could also save the error, // and notify the web site programmer(s) // Clear the accumulated data out of the response object Response.Clear(); // Create the route data configuration var rd = new RouteData(); rd.Values["controller"] = "Errors"; rd.Values["action"] = action; // Create then execute the controller method IController c = new Controllers.ErrorsController(); c.Execute(new RequestContext(new HttpContextWrapper(Context), rd)); }