MVC AreaRegistration

MVC AreaRegistration

AreaRegistration.RegisterAllAreas(); You may have seen it under Application_Start event. What it does?
There might be multiple sections like Administrator, Users, Bloggers, Writers, Advertise, Forums, Billing or department and so on of your web application. It becomes very difficult to manage all controllers at one place. So there is a way to register such areas and add controllers init.

Right click on MVC project to add new Area

Area Registration in MVC

Add new Area and name it as Administrator.
This will create Model, view and controller folder structure for you along with web.config.
MVC AreaRegistration 

And form here you are free to add your controllers and views specific to Administrator section.

using System.Web.Mvc;

namespace Req.Web.Api.Areas.Administrator
{
    public class AdministratorAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Administrator";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Administrator_default",
                "Administrator/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

Note: When you create new area inside an application, it creates new class derived from AreaRegistration. A new class overrides areaname property and it also registers routes for it.

Tags:

Linq Union and intersect ExampleJquery Dropdown Selected ValueHow to get Jquery selected optionWeb Hosting Providers

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.