If I am registering the route to an area (say it’s called Admin) in the global.asax file rather than the area’s AdminAreaRegistration.cs file, is there any reason why I can’t delete the AdminAreaRegistration.cs file? Is there any other code in the framework that may call into it at some stage which might throw an exception if it is missing?
As asked in comments, here is the code to register an Area in global.asax
routes.MapRoute(
"AdminAreaRoute",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "Payntbrush.Presentation.Demo.MVC3.Areas.Admin.Controllers" }
).DataTokens.Add("Area", "Admin");
routes.MapRoute(
"SiteAreaRoute",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { controller = "/|Home|Account" }, // Constraint's on the URL (second param above) {controller} segment
new string[] { "Payntbrush.Presentation.Demo.MVC3.Areas.Site.Controllers" }
).DataTokens.Add("Area", "Site");
The key is in using the DataTokens collection, as highlighted in this excellent post by Phillip Haydon. You can add as many as you want, but make sure you put the root site area after the explicitly named areas so that {controller}/{action}/{id} doesn’t catch all the requests before the other Map Routes can.
I’ve deleted these files and haven’t had any problems so far. I’m going to assume that it is OK until I run into any issues.