asp.net - Manually replicating AreaRegistration.RegisterAllAreas to load only select Areas? -


i'm quite new asp.net , thinking of way create multiple frontend areas different themes. area routes collide need manually load relevant area want use active frontend theme.

i'd different areas , not sets of views share models , controllers (easily achieved custom razorviewengine) models / controllers might differ radically each individual theme.

can done? or can in way?

so instead of arearegistration.registerallareas i'd register backend area , 1 of frontend areas (even if multiple available).

having had little success of getting answer, decided post solution here , sadly answer own question.

given volatile load order of arearegistrations, ended replacing arearegistration.registerallareas(); with:

static void registerarea<ar>(routecollection routes, object state)     ar : arearegistration {     var registration = activator.createinstance(typeof(ar)) arearegistration;     var context = new arearegistrationcontext(registration.areaname, routes, state);     var namespaceset = registration.gettype().namespace;     if (!string.isnullorempty(namespaceset))     {         // important relatively resolve controllers         context.namespaces.add(namespaceset + ".*");     }     registration.registerarea(context); } 

this how used code:

registerarea<areas.backend.backendarearegistration>(routetable.routes, null); registerarea<areas.frontend.frontendarearegistration>(routetable.routes, null); 

this allows decide order of areas manually. useful when have {*anything} directive in frontend routes might end loaded before backend routes.


Comments