I’ve been scouring the web for a solution for this the past couple days and I’m not finding much. Hopefully I’m not using the right terminology and it’s an easy thing to do.
I would like to use a path like:
/{projectId}
And have a place somewhere early on in the life-cycle where I have access to the route value dictionary that I can query a database or a session object to get the controller name to use for this request. Then be able to specify the controller to use route.Values["controller"] = controllerName; and have the request be made through that controller with all the jazz of request parameters and the like.
Is it possible?
I’m currently using areas, and have paths like:
/ProjectType1/{projectId}
/ProjectType2/{projectId}
but I’m finding it a real headache dealing with areas in all the Html.Link‘s and hate defining new areas for each project type. I would love to find something more dynamic.
You could write a custom route:
and then register it:
Now:
/1will invokeFooController/Index/2will invokeBarController/Index/3will invokeBazController/Index/something_elsewill throw 404 Not found