I have a really interesting case:
I have a site where this is already working
But I'd also like these urls to work as well
the farm part is fake, it doesn't do anything except to exist for SEO, there is no corresponding controller or action associated with it
Essentially, I have a ton of routes already, but I'd also like the site to behave exactly the same if "farm" is appended after the "mysite" the hostname. So it's kind of like a subdirectory behaving exactly like going on the main site.
You can add a route with constraint. Make sure it's above the default route.
routes.MapRoute(
"Farm", // Route name
"farm/{controller}/{action}", // URL with parameters
new { controller = "Home", action = "Index"} // Parameter defaults
);
It just makes sure URLs starting with "farm" gets their controller name from 2nd segment and action name from the 3rd segment.
I assume that you have a FarmController, you can just have them rout to your farmcontroller
routes.MapRoute(
"Farm", // Route name
"Farm/{controller}/{action}", // URL with parameters
new { controller = "Farm", action = "Index"} // Parameter defaults
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With