Im in the process of moving our website from a crappy CMS over to a nice custom coded MVC website. Everything has gone smoothly so far but I'm having some issues with routing.
Our company sends out a lot of marketing emails and letters. In these we have the user go to Landing Pages so we can track how campaigns are doing, as well as offer more information. So in a letter it would say "visit www.OurSite.com/LandingPage". However, in MVC all the pages are placed in folders of their controllers by default.
So say I have a page called LP in my Home controller, so the url is www.OurSite.com/Home/LP
What I need is for it to become www.OurSite.com/LP like before, so our currently running marketing campaigns won't give a 404 once we launch the new website. Plus it's a lot nicer to type in so we wan't to keep using this for the future.
Based on this default route:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
I've tried creating something like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"LandingPage",
"{action}/{id}",
new { controller = "Home", action = "LandingPage", id = UrlParameter.Optional }
);
}
But it isn't solving my issue.
I've done some googling and it's all for really complex routing that doesn't really apply. I'm not really interested in making this ultra dynamic or anything. I have no problems making a new route each time we run a campaign.
I should also note, not everyone of these pages will be in the Home controller. So just having a route remove that won't work. There are many controllers our landing pages fall under.