【问题标题】:Asp.net MVC 3 routing area failAsp.net MVC 3 路由区失败
【发布时间】:2013-08-28 17:00:12
【问题描述】:

我有这条路线:

我的网站路由WebSite/Global.asax.cs:

namespace WebSite
{
    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes) {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            ...
            routes.MapRoute(
                "Default",
                "Authenticated/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                new[] { "WebSite.Controllers" }
            );      
            ...
        }

        void Application_Start()
        {
            ...
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
            ...
        }       
    }
}

WebSite/Areas/Admin/AdminAreaRegistration.cs 上的我的管理区域路由:

namespace WebSite.Areas.Admin
{
    public class AdminAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Admin";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Admin_default",
                "qwerty/Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new[] { "WebSite.Areas.Admin.Controllers" }
            );
        }
    }
}

我的网址:

WebSite: http://www.mywebsite.com/Authenticated/Controller/Action...
Admin: http://www.mywebsite.com/qwerty/Admin/Controller/Action...

我的问题:

使用网站 URL,我可以在不使用“qwerty/Admin”的情况下从管理区域调用控制器/操作,这是不对的。我该如何解决这个问题?

谢谢。

【问题讨论】:

  • 可能是您的管理员路由不适合您的控制器操作,因为您没有在路由中定义控制器。我的意思是“controller = “Home”语句。
  • @Andrey.Gubal 如果我在网站和管理区域有两个同名的控制器,也会出现同样的问题,通过这个我将命名空间放在路由中,但没有解决任何问题。跨度>

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing asp.net-mvc-areas


【解决方案1】:

只需将此代码放在每个 MapRoute 之后。它应该工作!

.DataTokens["UseNamespaceFallback"] = false;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 2011-07-03
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多