I am creating a site where I would like to have dynamically added pages. Because of this, I would like to have a simpler URL. What I am aiming for is a URL like the following:
http://www.mysite.com/my-page-url
Rather than a URL like the following:
http://www.mysite.com/pageController/my-page-url
MVC URLs tend to work like this: |url|/|controller|/|action|/|params|
What I would like to do is have: |url|/|params|
For the above URL, if the values of params does not equal the name of a controller, then I would like to pass those params to PageContoller.ProcessDynamicPage.
Depending on what your default params are, you could create a route constraint
This would work if your parameter is an integer.
If your default params are strings or something and you can’t create a regex, or something that can’t implement
IRouteConstraintyour best bet it to create a matching action for each of your controllers that way when it falls through the default you’ve already attempted to do the matching.If you have a lot of controllers, you should probably really look into how to create the constraint for what you’re expecting.