4

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Cesar
  • 3,519
  • 2
  • 29
  • 43
  • May be your Admin route doesn't fit to your controller actions, because you didn't define controller in route. I mean "controller = "Home" statement. – Andrey Gubal Aug 28 '13 at 19:35
  • @Andrey.Gubal Will give the same problem if I have two controllers with the same name in website and admin area, by this I put the namespaces in routes, but didn't solved anything. – Cesar Aug 28 '13 at 19:52

1 Answers1

2

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

.DataTokens["UseNamespaceFallback"] = false;
Zote
  • 5,343
  • 5
  • 41
  • 43