What I'm trying to do is dynamic routing for my application.
For instance, in Application_BeginRequest() I want to get the current controller and determine if it exists. If not, I want to add a set of routes that override the default routing so that my url looks like this
mysite.com/term from database
But, if the "term from database" is a valid controller, I want it to use the default routing
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
I already have my routes the way I want. Now I just need to get the current controller and determine if it exists. If I do not add my custom routes, I recieve this error:
The IControllerFactory 'MySite.Web.UnityControllerFactory' did not return a controller for a controller named 'term from database'.
Is there a way to use unity from the global to determine if the controller exists?
Thanks!