ASP.NET MVC路由在Azure中 [英] ASP.NET MVC Routing in Azure

查看:83
本文介绍了ASP.NET MVC路由在Azure中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个最近被另一家开发商MVC'd一个Azure的Web角色项目。据开发商的应用程序没有问题,当它自己的运行工作(即一个简单的Web应用程序)。然而,当我尝试在Azure云服务的上下文中运行它,我看到了一些404的错误。我怀疑自己是不是与路由完全正确。下面是目前的RegisterRoutes方法的缩写版本这是Global.asax.cs中的一部分:

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 = "" }
    );}

在应用程序启动时,将显示账户控制器的Index操作正确的观点。但是,如果我尝试,如果我改变的方法来此导航到配置,我收到了404 Converesly:

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 = "" }
    );}

我从配置控制器的Index操作正确的观点,但我不能前往帐户视图。

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

我猜这是一个简单的问题解决了,但不知道究竟是什么做的目的是MVCAzure的应用程序,并成为新的MVC有我打我的头在墙上。

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.

下面就是在那里我遇到此问题的机器的配置:
Windows 7旗舰版与IIS 7.0中
Visual Studio 2008的SP1
ASP.NET MVC 1.0
Windows Azure的SDK 1.0

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

思考?

推荐答案

尝试使用我的路由调试。它可以帮助你了解这是怎么回事。 http://haacked.com/archive/2008/03/13 /url-routing-debugger.aspx

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

这很奇怪,该行为将在当地不同比Azure上。此外,你应该张贴您的控制器code(删除的动作方法的内容,我们只需要看到的方法签名)。

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).

如果我不得不做出一个胡乱猜测,我猜你配置的路由(你给了第一个例子),需要补充的id =,在默认设置部分。

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.

这篇关于ASP.NET MVC路由在Azure中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆