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

Daniel Lo Nigro lists at dan.cx
Sun Dec 23 03:17:42 UTC 2012


I fixed this but Github is currently down :(

I'll submit my fix as a pull request once Github is back up.


On Sat, Dec 22, 2012 at 7:32 PM, Daniel Lo Nigro <lists at dan.cx> wrote:

> 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
> routes.MapRoute(
> name: "BlogHome",
> url: "blog",
>  defaults: new { controller = "Blog", action = "Index", page = 1 }
> );
> routes.MapRoute(
> 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
> use:
>
> 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)
>
> Thanks,
>  - Daniel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20121223/beaaf79e/attachment.html>


More information about the Mono-devel-list mailing list