我有一个 Azure Web 角色项目,该项目最近由另一位开发人员进行了 MVC。根据开发人员的说法,该应用程序在自己运行时没有问题(即作为一个简单的 Web 应用程序)。但是,当我尝试在 Azure 云服务的上下文中运行它时,我看到了许多 404 错误。我怀疑路由有些不对劲。这是 Global.asax.cs 中的当前 RegisterRoutes 方法的缩写版本:

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

当应用程序启动时,会显示来自帐户 Controller 的索引操作的正确 View 。但是,如果我尝试导航到配置,我会得到 404。实际上,如果我将方法更改为:
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 = "" }
    );}

我从配置 Controller 的索引操作中获得了正确的 View ,但我无法导航到帐户 View 。

我猜这是一个需要解决的简单问题,但不知道对 Azure 应用程序“MVC”到底做了什么,并且是 MVC 的新手,这让我把头撞在墙上。

这是我遇到此问题的机器的配置:
带有 IIS 7.0 的 Windows 7 Ultimate
视觉工作室 2008 SP1
ASP.NET MVC 1.0
Windows Azure SDK 1.0

想法?

最佳答案

尝试使用我的路由调试器。它可以帮助您了解正在发生的事情。 http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

奇怪的是,本地的行为与 Azure 中的不同。此外,您应该发布您的 Controller 代码(删除操作方法的内容,我们只需要查看方法签名)。

如果我不得不做一个疯狂的猜测,我猜你的配置路由(在你给出的第一个例子中)需要在默认部分添加 id=""。

关于asp.net-mvc - Azure 中的 ASP.NET MVC 路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2103223/

10-12 18:39
查看更多