【问题标题】:I can't get areas working in VS2010我无法获得在 VS2010 中工作的区域
【发布时间】:2010-05-02 01:57:34
【问题描述】:

我刚刚从 VS2010 RC 升级到 RTM。现在我的区域不工作了。我有一个带有 Home 控制器和 Action 方法 Index() 的 Profile 区域。

如果我尝试:http://localhost:4951/profile 我收到 404 错误,提示找不到资源。如果我尝试http://localhost:4951/profile/home 我会得到同样的错误。但是,如果我尝试http://localhost:4951/profile/home/index,则会返回视图。

这是我的 ProfileAreaRegistration:

公共类 ProfileAreaRegistration :AreaRegistration { 公共覆盖字符串 AreaName { 得到 { 返回“个人资料”; } }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Profile_Unlock",
            "Profile/Unlock/{userID}/{unlockID}",
            new { controller = "Unlock", action = "Index" },
            new { userID = new GuidRouteConstraint(), unlockID = new GuidRouteConstraint() }
        );

        context.MapRoute(
            "Profile_default",
            "Profile/{controller}/{action}/{id}",
            new { action = "Home", id = UrlParameter.Optional }
        );
    }

有人知道怎么回事吗?

【问题讨论】:

    标签: visual-studio-2010 asp.net-mvc-2


    【解决方案1】:

    使用路由调试器找出正在应用的路由

    http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx

    【讨论】:

    • 成功了!不过还有一个问题。我在另一个区域中有一个自定义路由约束,如下所示: context.MapRoute("Account_Users", "Account/Users/{action}/{pageNumber}/{pageSize}/{filter}/{orderBy}", new { area = "Account", controller = "Users", action = "List", pageNumber = 1, pageSize = 20, filter = "all", orderBy = "name" }, new[] { "NS.Web.Areas.帐户” });路由测试器显示它是第一个匹配的路由,但我仍然收到 404 错误。关于可能导致这种情况的任何想法?
    • List 方法永远不会被击中。不过,我想通了。我删除了路由定义中的命名空间声明,它可以工作。我不知道为什么会有所作为,但现在可以正常工作了。
    猜你喜欢
    • 2021-09-15
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    • 1970-01-01
    相关资源
    最近更新 更多