7
Vote

RegisterRoutes method has been removed in MVC 4

description

Easy workaround in global:


protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

        RegisterRoutes(RouteTable.Routes);

    }

    public void RegisterRoutes(RouteCollection routes)
    {
        RouteConfig.RegisterRoutes(routes);
    }

comments

ztsmith wrote Sep 19, 2012 at 5:03 PM

It would be nice if the restriction of needing to have the RegisterRoutes method defined the MvcApplication file. When there are a large amount of routes it is nice to put this in another class. Plus obviously .NET 4 separates the routes out by default now.

bartvanderwal wrote Mar 19, 2016 at 2:12 PM

This is a great fix!

However after doing this I then get another error:

An exception of type 'System.InvalidOperationException' occurred in MvcRouteUnitTester.dll but was not handled in user code

Additional information: There are no routes defined. Make sure you have defined at least one route.

This is because I am using MVC5 not 4. I am now switching to another route tester package specifically for MVC 5:
https://github.com/AnthonySteele/MvcRouteTester