开发者

ASP.NET MVC Routing in Azure

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. 开发者_如何学JAVAHere'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?


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.


Haacked: Thanks for pointing me to the debugger. That helped me hunt down the issue in a matter of minutes.

The answer was much simpler than I thought. It all had to do with the following line of code:

routes.IgnoreRoute("{Services}/{*pathInfo}");

I put this line in to help resolve an issue I was having with ASP.NET MVC and WCF RIA Services (more info on that here). The curly braces shouldn't be there. I don't want to replace Services. The code should look like this:

routes.IgnoreRoute("Services/{*pathInfo}");

You can read a full write-up here.


I don't think this is your problem, but you might verify that the System.Web.Mvc reference has its Copy Local = true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜