Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: Many routes -> always only one controller

I have very simple question. My site, based on ASP.NET MVC, can have many urls, but all of them should bring to the one controller. How to do that?

I suppose I need some magic in Global.asax but I don't know how to create route that will redirect any url to the specific controller.

For example I have url /about, /product/id etc. but all of them should be really bring to the content/show where the parts of url will be recognized and the decision what information to show will be make. It's some like CMS when you cannot define routes in advance. Is this information enough?

Thanks

like image 847
mimic Avatar asked Nov 29 '22 18:11

mimic


1 Answers

This sounds like a horrible idea, but, well, if you must;

routes.MapRoute(
    "ReallyBadIdea",
    "{*url}",
    new { controller = "MyFatController", action = "MySingleAction" }
    );

This routes everything to a single action in a single controller. There's also {*path} and other URL patterns should you want slightly more flexibility.

like image 52
blowdart Avatar answered Dec 13 '22 20:12

blowdart