I've got an Area in my ASP.NET MVC4 app that I register in Global.asax. Anytime I try to access the default route at:
whateverurl.tld/Area
ASP.NET MVC4 adds a trailing slash to it such that it looks like:
whateverurl.tld/Area/
and Visual Studio 2012's embedded IIS server throws back a 404.
However, if I browse to 'whateverurl.tld/Area/Index', it shows up. I've got another route that uses EXACTLY the same default route (sans the controller name), and when I access that route in my browser, it goes to 'whateverurl.tld/OtherArea' WITHOUT the trailing slash. As expected, without the trailing slash, the index for the controller is shown.
This is driving me absolutely insane. The configuration for each area is nearly identical. I can come up with some kind of workaround, but I really REALLY need to know what's causing this behavior to avoid it in the future.
Area 1 (Not Working):
context.MapRoute(
"Area1_default",
"Area1/{action}/{id}",
new { controller = "Area1", action = "Index", id = UrlParameter.Optional }
);
Area 2 (Working):
context.MapRoute(
"Area2_default",
"Area2/{action}/{id}",
new { controller = "Area2", action = "Index", id = UrlParameter.Optional }
);
Global.asax.cs:
Area1Registration aReg1 = new Area1Registration();
AreaRegistrationContext a1c = new AreaRegistrationContext(aReg1.AreaName, RouteTable.Routes);
aReg1.RegisterArea(a1c);
Area2Registration aReg2 = new Area2Registration();
AreaRegistrationContext a2c = new AreaRegistrationContext(aReg2.AreaName, RouteTable.Routes);
aReg2.RegisterArea(a2c);
UPDATE: I used a route debugger to see what route it matches. It matches no routes. Not particularly sure what the hell is going on. I can't get the route debug info to display because apparently the '/' is getting added before the route matching is done.
context.MapRoutereplace"Area1/{action}/{id}",with"Area1/{controller}/{action}/{id}",