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.

/content/images/2015/08/nuget-1.png

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:

PM> Install-Package MvcAreasForEPiServer  

2) Register Mvc Areas. You have plenty of places to register this code fragment (Application_Start, Global.RegisterRoutes, InitializableModule, etc).

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.

[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]

Wałdis Iljuczonok

Software architect, lead technologist and Visual Studio ALM & TFS evangelist, technical fellow. Focus on solution research, new technologies analysis and enterprise designing.

http://blog.tech-fellow.net
riga.lv

comments powered by Disqus