How can I, when executing a controller action, take a Uri (not the one requested) and invoke the action from the controller that would have been executed had that Uri been t
For the correct answer, I'd prefer do something like this to let MVC handle creating controllers rather than creating myself.
var routeData = new RouteData();
// controller and action are compulsory
routeData.Values["action"] = "index";
routeData.Values["controller"] = "foo";
IControllerFactory factory = ControllerBuilder.Current.GetControllerFactory();
var requestContext = new RequestContext(new HttpContextWrapper(yourHttpContextObject), routeData);
var controller = factory.CreateController(requestContext, "FooController");
try
{
controller.Execute(requestContext);
}
finally
{
factory.ReleaseController(controller);
}
This would assure you that your Foo controller is getting the same behavior as other controllers.