[Mono-dev] Issue with URL routing not properly utilising default parameters

Daniel Lo Nigro lists at dan.cx
Sat Dec 22 08:32:13 UTC 2012

I'm curious as to if anyone has experienced this issue before. Given the
following routes:

// Blog home page - Don't include page number in URL for first page
name: "BlogHome",
url: "blog",
defaults: new { controller = "Blog", action = "Index", page = 1 }
name: "BlogHomePage",
url: "blog/page-{page}",
defaults: new { controller = "Blog", action = "Index" },
constraints: new { page = @"\d+" }

And this ASP.NET MVC action:
public ActionResult Index(int page = 1) { ... }

Microsoft .NET is smart enough to use the first route if you build a URL
with page = 1 (something like Url.Action("Index", "Blog", new { page = 1 })
in ASP.NET MVC) and the second route when the page number isn't 1. However,
Mono is always using the second route, even when page = 1. In theory it
should be matching the first rule as it's added first (and thus should have
higher priority).

I've worked around this in my code by explicitly specifying which route to

public static string BlogIndex(this UrlHelper urlHelper, int page = 1)
return page == 1
? urlHelper.RouteUrl("BlogHome")
: urlHelper.RouteUrl("BlogHomePage", new { page = page });

I have reported this as a bug (
https://bugzilla.xamarin.com/show_bug.cgi?id=9116) but I'm curious as to if
it's a known issue with Mono's URL routing implementation.

I was going to try the Microsoft .NET implementation with Mono but it looks
like Microsoft's implementation is in the core System.Web assembly in .NET
4.0 (instead of being in a separate System.Web.Routing assembly)

 - Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20121222/be862225/attachment.html>

More information about the Mono-devel-list mailing list