I upgraded my project to ASP.NET 4 RTM using ASP.NET MVC 2.0 RTM today.
I previously used ASP.NET 3.5 with ASP.NET MVC 2.0 RTM .
Some of my routes do not work all of a sudden, and I donโt know why. I'm not sure if something has changed between 3.5 and 4.0 - or is it a regression type problem in RTM 4.0. (I have never tested my application with 4.0 before).
I like to use Url.RouteUrl("route-name", routeParams) to avoid ambiguity when creating URLs. Here is my route definition for the gallery page. I want imageID be optional (you get a thumbnail page if you didn't specify it).
// gallery id routes.MapRoute( "gallery-route", "gallery/{galleryID}/{imageID}/{title}", new { controller = "Gallery", action = "Index", galleryID = (string) null, imageID = (string) null, title = (string) null} );
In .NET 3.5 / ASP.NET 2.0 RTM / IIS7
Url.RouteUrl("gallery-route", new { galleryID = "cats"}) => /gallery/cats Url.RouteUrl("gallery-route", new { galleryID = "cats", imageID = "4") => /gallery/cats/4 Url.RouteUrl("gallery-route", new { galleryID = "cats", imageID = "4", title = "tiddles") => /gallery/cats/4/tiddles
In .NET 4.0 RTM / ASP.NET 2.0 RTM / IIS7
Url.RouteUrl("gallery-route", new { galleryID = "cats"}) => null Url.RouteUrl("gallery-route", new { galleryID = "cats", imageID = "4") => /gallery/cats/4 Url.RouteUrl("gallery-route", new { galleryID = "cats", imageID = "4", title = "tiddles") => /gallery/cats/4/tiddles
Previously, I could only provide galleryID , and everything else would be ignored in the generated URL. But now, it seems, I need to specify all the parameters before the title - or he refuses to determine the URL.
Incoming URLs work fine for /gallery/cats , and it displays correctly in this rule with imageID and title , which are set to null in my controller.
I also tested INCOMING routes from http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx and they all work fine.