Asp.net MVC 2 adds the area feature so that we can perform parallel development between each area without affecting each other. However, you must call the arearegistration. registerallareas () method in the application_start () method of Global. asax. CS to register the ingress of the area. I want to dynamically register an area based on my needs. If I have an idea, I have to do it. The answer is yes.
First, you do not need to create a class that inherits from arearegistration, and then write the route registration of each area to global. asax. CS.
Public static void registerroutes (routecollection routes) {routes. ignoreroute ("{resource }. axd/{* pathinfo} "); routes. add (new route ("price/{controller}/{action}/{ID}", new mvcroutehandler () {defaults = new routevaluedictionary (New {controller = "home ", action = "Index", id = urlparameter. optional}), datatokens = new routevaluedictionary (New {area = "price", namespaces = new [] {"sobey. mam. mvcweb. areas. price "}})}); routes. add (new route ("root/{controller}/{action}/{ID}", new mvcroutehandler () {defaults = new routevaluedictionary (New {controller = "home ", action = "Index", id = urlparameter. optional}), datatokens = new routevaluedictionary (New {area = "root", namespaces = new [] {"sobey. mam. mvcweb. areas. root "}})}); routes. maproute ("default", // route name "{controller}/{action}/{ID}", // URL with parameters new {controller = "login ", action = "Logon", id = urlparameter. optional} // parameter defaults );}
Note that you must declare areaname and save it to route. datatttokens. Otherwise, the corresponding area directory cannot be located.