4

我有这条路线:

我的网站路线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”,这是不对的。我怎样才能解决这个问题?

谢谢你。

4

1 回答 1

2

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

.DataTokens["UseNamespaceFallback"] = false;
于 2013-08-28T20:17:19.050 回答