7

I know this error has popped up for people before, but this seems to be a bit of a special case.

I've been working on setting up a SPA with ReactJS on top of ASP.NET MVC 4. I've had no problem getting things working on my machine. However, the weird issue I'm seeing is that it's not working on any other machines for other devs. As far as I've seen, I don't have any files that aren't checked in under source control. I've made use of the RouteDebugger and I see the proper route being caught.

The route I'm using for this SPA is /V2/Home. So I have an Area called "V2", an MVC controller in the area called "HomeController" and it has a view called "Index". I setup a catchall in the V2AreaRegistration.

public override void RegisterArea(AreaRegistrationContext context)
{
   context.MapRoute(
       "V2_default",
       "V2/{*url}",
       new { area = "V2", controller = "Home", action = "Index" }
   );
}

Here's Application_Start in Global.asax.cs

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

    GlobalConfiguration.Configure(WebApiConfig.Register);           
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
    AuthConfig.RegisterAuth();

    AutoMapperConfiguration.Configure();
    Logger.Info("Application started");

    GlobalConfiguration.Configuration.EnsureInitialized(); 
}

I've gotten absolutely nowhere with this. I would love to get this solved. Feel free to ask for anything missing.

SnareHanger
  • 928
  • 11
  • 22
  • Do you have a HomeController in your main site as well? If so, you will need to specify the namespace to use here using the namespace parameter of MapRoute, otherwise MVC won't know which "HomeController" to use. Either that, or change the name to V2HomeController or something like that. – Erik Funkenbusch Apr 12 '15 at 23:53
  • Do a clean checkout to another folder on your machine and try running the site, or use something like WinMerge to compare the directories. – Tieson T. Apr 13 '15 at 05:38
  • @TiesonT. I've done that and it still works fine on my machine – SnareHanger Apr 13 '15 at 12:47
  • @ErikFunkenbusch There's no other HomeController anywhere in the project as far as I can see. – SnareHanger Apr 13 '15 at 14:51
  • What are you using for ReactJS routing? And have you tried altering your route to the full `V2/{controller}/{action}/{id}`? – Dave Alperovich Apr 16 '15 at 00:34
  • @DaveAlperovich I'm using react-router. I think I actually figured out what's happening. – SnareHanger Apr 16 '15 at 03:31

2 Answers2

3

I'm not sure exactly what it is, but I managed to fix my issue. It has something to do with how we're handling routing and authentication/permissions.

SnareHanger
  • 928
  • 11
  • 22
1

I can't explain how this would work on your machine, but not your colleagues machines.

It looks like your area registration doesn't know what namespace your controllers live in. Try adding a 4th argument to the MapRoute method call that declares the namespace of your new controllers:

public override void RegisterArea(AreaRegistrationContext context)
{
   context.MapRoute(
       "V2_default",
       "V2/{*url}",
       new { area = "V2", controller = "Home", action = "Index" },
       new string[] { "MyApplication.MyMvcProject.Areas.Controllers" } // Change this to the namespace of your area controllers.
   );
}
Adrian Thompson Phillips
  • 6,893
  • 6
  • 38
  • 69