Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC remap Catch-All parameter value and execute another valid route
    primarykey
    data
    text
    <p>I'm trying to construct the flexible URL routing.</p> <p>So the url like</p> <pre><code>en-US/ctrl/act/1/2 </code></pre> <p>should do the same as</p> <pre><code>ctrl/act/1/2 </code></pre> <p>and set the culture to en-US.</p> <p>Now I have achieved that by defining two routes as following:</p> <pre><code>routes.MapRoute( "Ctrl", "ctrl/{action}/{group}/{page}", new { controller = "Home", action = "Index", group = 1, page = 1 }, new { group = @"\d+", page = @"\d+" } ); routes.MapRoute("CtrlWithCulture", "{culture}/ctrl/{action}/{group}/{page}", new { culture = "", controller = "Home", action = "Index", group = 1, page = 1 }, new { culture = "[a-z]{2}-(?:[a-zA-Z]{2,4}-)*(?:[a-zA-Z]{2,4})", group = @"\d+", page = @"\d+" } ); </code></pre> <p>I have a base controller that is setting the culture based on the input parameter. But I want to have this functionality by default for all the routes, so I tried something like this.</p> <pre><code>Global.asax.cs: routes.MapRoute("RootWithCulture", "{culture}/{*rest}", new { controller = "Home", action = "Index", culture = "" }, new { culture = "[a-z]{2}-(?:[a-zA-Z]{2,4}-)*(?:[a-zA-Z]{2,4})" } ); MyController.cs public class MyController : Controller { ... protected override void OnActionExecuting(ActionExecutingContext context) { if (!String.IsNullOrEmpty(context.RouteData.Values["culture"].ToStringOrNull())) { this.SetCulture(String.IsNullOrEmpty(context.RouteData.Values["culture"]) context.RouteData.Values.Remove("culture"); // I'm stuck here! // I want to try other routes and find and execute the right one... </code></pre> <p>I'm not sure what would be the right approach to this...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload