1
votes

I have one Area and in AreaRegistration I defined namespace all controllers in area belongs to.

context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { controller="Home", action = "Index", id = UrlParameter.Optional },
                new[] { "MySite.Admin.Controllers" }             // Namespaces
            );

How to prevent controller in that area to be called even when not that route is matched. I.E. /home/index (without "admin" word at the beginning).

EXAMPLE:

If a have controller "MySite.Admin.Controllers.HomeController" which belongs to area root defined above. I want to forbid controller factory to search for that controller (i.e. throw exception) if it doesn't match route "Admin/{controller}/{action}/{id}" ("Admin" at the end). So if I type "home/index" (no "Admin" at the beginning) web site will throw an error that it can't find controller.

Hope i was clear enough.

1
Sorry couldn't understand your question, could you provide an example ?Mahesh Velaga

1 Answers

2
votes

Add a constraint to match the area!

Here is a nice read on route constraints.

If you want to write your own custom route constraint, then give the following a read

http://blogs.microsoft.co.il/blogs/bursteg/archive/2009/01/11/asp-net-mvc-route-constraints.aspx

Edit:

Remove the default route and make sure everything is scoped to areas, then home/index will throw an exception as it is not scoped to an area.