This project has moved and is read-only. For the latest updates, please go here.

Routing question

Sep 27, 2011 at 3:49 PM
Edited Sep 27, 2011 at 3:57 PM

For some reason I can't seem to get the routing functionality to work. If I leave off an extension to ProductReport then I get the default which is HTML. If I include an extension ProductReport.html I get a 404. I've tried explicitly adding the route in Global.asax, but to no avail. Is there some configuration issue I'm missing?

 

edit- This was related to using DefaultAppPool...

Nov 28, 2011 at 6:19 PM

So is it fixed now? If your app pool was running in Classic that would indeed cause this problem. Changing to Integrated Mode should resolve it

Dec 6, 2011 at 6:44 PM

I get this 404 error using the ASP.NET Development Servers.... is there a way to put that into Integrated Mode?

Dec 6, 2011 at 6:47 PM

The Dev Server should not be 404'ing. Can you paste your Global.asax? The MapReportRoute needs to be called before the default controller. Without that Route properly in there it will 404

Dec 6, 2011 at 6:56 PM

Tried also with IIS Express using integrated model and still get the 404 error.

Dec 6, 2011 at 6:58 PM

In Global.asax RegisterRoutes() did you MapReportingRoute before the default routes?



        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


            routes.MapReportingRoute();

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Doddle", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
        }
Dec 6, 2011 at 7:10 PM

Yes, but I have Areas also, so I'm not sure it's getting mapped correctly. Actually, considering it's a 404, I'm not even sure it's getting to the routing engine.?

Dec 6, 2011 at 7:16 PM

It doesn't appear to be. I haven't really tested how it would work with Areas. Let me give it a shot. But if you set a breakpoint in your Controller Action and it's not getting hit, it's definitely a routing problem

Dec 6, 2011 at 7:16 PM

Yep, confirmed it works with root controllers. Won't work with controllers in areas.

 

Dec 6, 2011 at 7:21 PM

Ok, so I manually added the route to the "XAreaRegistration.cs" files:

    public class XAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get { return "X"; }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute("XDoddleReport",
                    "X/{controller}/{action}.{extension}",
                    new { action = "Index" },
                    new { extension = new ReportRouteConstraint() }
                );

            context.MapRoute(
                "X_default",
                "X/{controller}/{action}/{id}",
                new {action = "Index", id = UrlParameter.Optional}
                );
        }
    }

Dec 6, 2011 at 7:25 PM

I've added a new extension method for registering Areas - I will check it in soon and will update the NuGet package with this and a few other updates.

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapReportingRoute();
            

            context.MapRoute(
                "Reporting_default",
                "Reporting/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }

 

May 2, 2012 at 4:43 PM

I installed the doddlereport sample project and was nailed by the order of the MapRoute.  Scratched my head for awhile as it was passing the Hack route check, used Salmon Zaks Application_BeginRequest code. Bingo saw it was going down the /controller/action/id path.

http://salmanzg.wordpress.com/2010/09/16/simple-aspnet-mvc-route-debugging/#comment-22

 

Moved the MapRoute, onward and upwards as they say.

Bubs

Oct 9, 2012 at 6:37 PM

I was starting with a clean slate in Visual Studio 2012 with Asp.NET 4.5 and MVC 4 - installing all Doddle related items from NuGet and was experiencing a similar 404 problem seemingly associated with routing.  It was not related to the order as mentioned above, but rather was resolved with the following addition to the web config

  <system.webServer>

<modules runAllManagedModulesForAllRequests="true">  

</modules>

...

</system.webserver>

 

credit: http://notebookheavy.com/2012/05/21/404-error-on-asp-net-4-5-on-iis-7/