Asp.Net Mvc Areas - Packed as NuGet
If you would want to add Asp.Net Areas support to your EPiServer site, you would need to copy some files from my previous blog post. Copying files from someone’s blog posts seems to be good idea, but it’s a bit problematic in case of updates or changes. If so, then we share common vision that by installing NuGet package, your project gets up-to-date support for Asp.Net Mvc Areas.
For that reason I packed up Asp.Net Mvc Areas support into NuGet package, for you guys. You may just need to install it and configure a bit if needed, to get things up and running.
Getting Started
1) Install NuGet package:
1
PM> Install-Package MvcAreasForEPiServer
2) Register Mvc Areas. You have plenty of places to register this code fragment (Application_Start
, Global.RegisterRoutes
, InitializableModule
, etc).
1
AreaConfiguration.RegisterAllAreas();
By default configuration setting to detect Mvc Area by controller (EnableAreaDetectionByController
) will be enabled.
Configuration
If you want to disable Mvc Area detection by controller, you can choose configuration settings to customize this behavior during areas registration procedure.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
public class ConfigureAreasSupportModule : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
AreaConfiguration.RegisterAllAreas(config =>
{
config.EnableAreaDetectionByController = true;
config.EnableAreaDetectionBySite = true;
});
}
public void Uninitialize(InitializationEngine context)
{
}
}
There are two configuration settings:
EnableAreaDetectionByController
: this setting will make sure that Mvc Area is detected while executing controller for particular content type in that area;EnableAreaDetectionBySite
: this setting will make sure that Mvc Area is detected when accessing EPiServer site that is also defined as Mvc Area;
More info about general insights of Mvc Area support for EPiServer sites: here More info about using Mvc Areas as EPiServer’s site discriminators: here
Happy slicing and dicing into areas!
[eof]
Comments powered by Disqus.