asp.net-mvc – Asp.net MVC 3路由区域失败

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – Asp.net MVC 3路由区域失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这条路线:

我在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);
            ...
        }       
    }
}@H_301_5@ 
 

我在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",new[] { "WebSite.Areas.Admin.Controllers" }
            );
        }
    }
}@H_301_5@ 
 

我的网址:

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

我的问题:

使用WebSite URL,我可以从管理区域调用控制器/操作,而不使用“qwerty / Admin”,这是不对的.我怎样才能解决这个问题?

谢谢.

解决方法

只需在每个MapRoute之后输入此代码即可.它应该工作!
.DataTokens["UseNamespaceFallback"] = false;@H_301_5@

猜你在找的asp.Net相关文章