Search code examples
turbine

MVC Turbine routes not registering


I've been setting up a project to run with MVC Turbine and have been having issues getting the IRouteRegistrators to be called. Another person on my team has had this issue in the past, but he can't remember what he had to do to resolve it.

The code for the setup is temporarily all in the Global.asax.cs file until this is worked out. The code I'm using looks similar to every tutorial I have seen, but it's included below anyways.

   public class MvcApplication : TurbineApplication
   {
      static MvcApplication()
      {
         ServiceLocatorManager.SetLocatorProvider (() => new StructureMapServiceLocator ());
      }

      protected void Application_Start ()
      {
         DeployDbMigrations ();
      }

      private void DeployDbMigrations ()
      {
         ...
      }
   }

   public class RouteRegistration : IRouteRegistrator
   {
      public void Register (RouteCollection routes)
      {
         routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");

         routes.MapRoute (
             "Default", // Route name
             "{controller}/{action}/{id}", // URL with parameters
             new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
         );

      }
   }

As I said, the IRouteRegistrator is not being called, so when I go to the home page, I will get a 404, even though the proper controller and view is set up.

The annoying thing is that I can create a similar project outside the current solution and it will work, but it will not work in the solution. (Although, I have tried copy-pasting the working project into the solution and that worked. But, that's no longer an option, since someone else has done some more work on the web project while I was figuring this out.)

Has anyone encountered this problem in the past, and/or know how to fix it?


Solution

  • Check the name of the assembly generated by your project. MVCTurbine filters out some assemblies by name when looking for registrations. If the name of your assembly contains any of the following it will not be checked for routes.

    • System
    • System.Web
    • mscorlib
    • MvcTurbine,
    • MvcTurbine.Web,
    • WebDev
    • CppCodeProvider

    Renaming the assembly should correct the issue.