Bug 9116 - System.Web.Routing doesn't properly utilise value-type default parameters
Summary: System.Web.Routing doesn't properly utilise value-type default parameters
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-12-22 02:34 UTC by Daniel Lo Nigro
Modified: 2012-12-23 08:09 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Example project demonstrating the issue (1.06 MB, application/x-gzip)
2012-12-22 02:34 UTC, Daniel Lo Nigro
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Daniel Lo Nigro 2012-12-22 02:34:15 UTC
Created attachment 3123 [details]
Example project demonstrating the issue

Given routes like this:

// Blog home page - Don't include page number in URL for first page
routes.MapRoute(
	name: "BlogHome",
	url: "blog",
	defaults: new { controller = "Home", action = "BlogIndex", page = 1 }
);
routes.MapRoute(
	name: "BlogHomePage",
	url: "blog/page-{page}",
	defaults: new { controller = "Home", action = "BlogIndex" },
	constraints: new { page = @"\d+" }
);

Whenever page=1 is used in the route, it should resolve to /blog, and whenever any other number is used, it should resolve to /blog/page-x. That is, the following Razor (.cshtml) view:
@Url.Action("BlogIndex", "Home", new { page = 1 });
@Url.Action("BlogIndex", "Home", new { page = 2 });

Should display the following:
/blog/page-1
/blog/page-2

This works in Microsoft .NET, but Mono appears to be ignoring the first route and is outputting the following:
/blog/page-1
/blog/page-2

Another issue I've encountered is with the following routes:
routes.MapRoute(
	name: "BlogAdminPostsPublished",
	url: "blog/admin/posts/published",
	defaults: new { controller = "Home", action = "Posts", published = true }
);
routes.MapRoute(
	name: "BlogAdminPostsUnpublished",
	url: "blog/admin/posts/unpublished",
	defaults: new { controller = "Home", action = "Posts", published = false }
);

UrlHelper.Action is not using these routes in Mono - The following:
@Url.Action("Posts", "Home", new { published = true })
@Url.Action("Posts", "Home", new { published = false })

Should output this:
/blog/admin/posts/published
/blog/admin/posts/unpublished

But it is outputting this:
/Home/Posts?published=True
/Home/Posts?published=False

I've attached a test project which demonstrates this issue. This app runs under Mono 3.0 (via XSP) and on Windows via IIS or Cassini.
Comment 1 Daniel Lo Nigro 2012-12-22 02:35:25 UTC
Sorry, for the first one, I meant that the output should be as follows:
/blog
/blog/page-2
Comment 2 Daniel Lo Nigro 2012-12-22 22:16:32 UTC
I've fixed this but Github is currently down. I'll submit my fix as a pull request once Github is up again.
Comment 3 Daniel Lo Nigro 2012-12-23 00:25:16 UTC
Patch submitted via Github: https://github.com/mono/mono/pull/526