What Are Areas?
Areas let you partition a large ASP.NET MVC application into smaller functional groups, each with its own Controllers, Models, and Views folders, typically used to isolate a module like Admin or Blog from the main application. Each area lives under an Areas/{AreaName} folder and is registered independently so the routing engine knows how to dispatch requests into it.
Cricket analogy: IPL franchises like Mumbai Indians run separate academies for batting, bowling, and fielding so each unit trains independently under its own coaching staff, similar to how MVC Areas let a large app split into self-contained modules like Admin and Storefront.
Creating and Registering an Area
Right-clicking the project and choosing Add > Area scaffolds an Areas/Admin folder with Controllers, Models, Views subfolders and an AdminAreaRegistration.cs file. That class overrides AreaName and RegisterArea, mapping a route whose pattern typically includes the literal Admin segment, and Global.asax.cs must call AreaRegistration.RegisterAllAreas() before RouteConfig.RegisterRoutes so area routes are matched first.
Cricket analogy: A tournament organizer registers each franchise's fixture list separately with the board before the season starts, similar to how AreaRegistration.RegisterAllAreas() in Global.asax calls each Area's own RegisterArea method to wire up its routes at startup.
// Areas/Admin/AdminAreaRegistration.cs
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName => "Admin";
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "MyApp.Areas.Admin.Controllers" }
);
}
}
// Global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}Area Routing and Namespaces
Because both the root application and an Area can each contain a controller with the same class name, such as HomeController, the routing engine can throw an ambiguous controller exception unless namespaces are supplied. Passing an explicit namespaces array to MapRoute, as generated by the Add Area scaffolding, scopes route matching to the correct assembly namespace and avoids the collision.
Cricket analogy: Two different domestic leagues both having a team called 'Warriors' forces broadcasters to specify the state name to avoid confusing viewers, similar to how two Areas both containing a HomeController require namespace hints in MapRoute to resolve correctly.
If you rename or copy a controller between Areas without updating the namespaces parameter in MapRoute, you can get a runtime 'Multiple types were found that match the controller named X' exception. Always keep the namespaces array in each AreaRegistration in sync with the actual controller namespace.
Linking Between Areas
To link into an Area from outside it, pass an area route value, e.g. Html.ActionLink("Manage", "Index", "Home", new { area = "Admin" }, null); to link from inside an Area back to the root application or another area, you must explicitly set area = "" or the link generator will assume you mean the current area. Url.Action follows the same rule when building links inside partial views shared across areas.
Cricket analogy: A stadium's signage directs fans from the general concourse to the VIP hospitality section using a specific corridor label, and a separate sign routes them back to the main concourse, mirroring Html.ActionLink specifying area = "Admin" to link into the Admin area and area = "" to link back to the root.
Register areas before the default route: AreaRegistration.RegisterAllAreas() must run before RouteConfig.RegisterRoutes(RouteTable.Routes) in Application_Start, otherwise the default root route may greedily match URLs intended for an area.
- Areas partition a large MVC app into self-contained modules, each with its own Controllers, Models, and Views folders.
- Visual Studio's Add > Area scaffolding creates an AreaRegistration subclass that maps the area's route.
- AreaRegistration.RegisterAllAreas() must be called before RouteConfig.RegisterRoutes in Application_Start.
- Identically named controllers in different areas require explicit namespaces in MapRoute to avoid ambiguous match exceptions.
- Linking into an area requires an area route value; linking out requires explicitly setting area = "".
- Areas are ideal for isolating admin panels, APIs, or large functional modules from the main application.
- Each area's routes are matched before the root application's default route when registered correctly.
Practice what you learned
1. What file does Visual Studio generate when you add a new Area named 'Admin'?
2. Which call must happen before RouteConfig.RegisterRoutes in Application_Start for areas to route correctly?
3. What causes a 'Multiple types were found that match the controller named X' exception with Areas?
4. How do you link from within an Area's view back to a controller in the root application?
5. Which of the following is a typical use case for Areas?
Was this page helpful?
You May Also Like
Unit Testing MVC Controllers
Learn practical techniques for isolating and testing ASP.NET MVC controller actions using xUnit or NUnit with Moq, including ActionResult assertions and model validation testing.
Deploying MVC Applications
A practical guide to shipping ASP.NET MVC applications to production using Web Deploy, Azure App Service, web.config transforms, and IIS application pool configuration.
ASP.NET MVC Interview Questions
A focused review of the most commonly asked ASP.NET MVC interview topics — architecture, routing, filters, model binding, and state management — with concrete explanations.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics