R – ASP.NET MVC Routing in Azure

asp.net-mvcazure

I have an Azure Web Role project that was recently MVC'd by another developer. According to the developer the app works with no problem when run on it's own (i.e. as a simple web app). However, when I try to run it in the context of the Azure cloud service, I'm seeing a number of 404 errors. I suspect something is not quite right with the routing. Here's an abbreviated version of the current RegisterRoutes method that's part of Global.asax.cs:

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

routes.MapRoute(
        "Configuration", 
            "Configuration",
            new { controller = "Configuration", action = "Index" }
            );

routes.MapRoute(
    "Default",                                              
            "{controller}/{action}/{id}",                           
            new { controller = "Account", action = "Index", id = "" }
    );}

When the app starts up, the correct view from the Account controller's Index action is displayed. However if I try to navigate to Configuration I get a 404. Converesly if I change the method to this:

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

routes.MapRoute(
        "Account", 
            "Account",
            new { controller = "Account", action = "Index" }
            );

routes.MapRoute(
    "Default",                                              
            "{controller}/{action}/{id}",                           
            new { controller = "Configuration", action = "Index", id = "" }
    );}

I get the correct view from the Configuration controller's Index action, but I can't navigate to the Account view.

I'm guessing this is a simple problem to solve, but not knowing what exactly was done to "MVC" the Azure app and being new to MVC has me beating my head into the wall.

Here's the configuration of the machine where I'm encountering this issue:
Windows 7 Ultimate with IIS 7.0
Visual Studio 2008 SP1
ASP.NET MVC 1.0
Windows Azure SDK 1.0

Thoughts?

Best Answer

Try using my Routing Debugger. It can help you understand what's going on. http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

It's weird that the behavior would be different locally than in Azure. Also, you should post your controller code (remove the contents of the action methods, we just need to see the method signatures).

If I had to make a wild guess, I'd guess your Configuration route (in the first example you gave) needs to add id="" in the defaults section.

Related Topic