Question

I have this routes:

My website route on 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);
            ...
        }       
    }
}

My Admin Area route on 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" }
            );
        }
    }
}

My URLs:

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

My problem:

With WebSite URL I can call Controllers/Actions from Admin Area, without use "qwerty/Admin", and this is not right. How can I fix this?

Thank you.

Was it helpful?

Solution

Just put this code after each MapRoute. It should work!

.DataTokens["UseNamespaceFallback"] = false;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top