I'm trying to create URIs that look a little something like this:
http://hostname/mobile/en/controller/action
for mobiles OR http://hostnamem/en/controller/action
for desktop (non mobiles)
My Route table currently looks like this (Global.asax.cs) ` routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Mobile", // Route name
"mobile/{language}/{controller}/{action}/{id}", // URL with parameters
new { language = "en", controller = "Route", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new { language = @"en|us" } // validation
);
routes.MapRoute(
"Default", // Route name
"{language}/{controller}/{action}/{id}", // URL with parameters
new { language = "en", controller = "Route", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new { language = @"en|us" } // validation
); `
The problem occurs when I try to do a
return RedirectToAction("Add", "User");
It always redirects the desktop browser from /en/User/List
to /mobile/en/User/Add
when I want it to go to /en/User/Add
The Mobile version works correctly but I believe this is because the first "Mobile" route is always been seen to be the route that matches even if it doesn't have /mobile/ at the start.
I'm trying to use the same Controller for both versions but am stuck at it always redirecting to the Mobile route. This means RedirectToRoute
isn't prefect as I want dynamic routes.
Thanks for your help