Skip to content

Instantly share code, notes, and snippets.

@alasvant
Created January 12, 2020 12:57
Show Gist options
  • Save alasvant/e74ce50a9f959212dcbce11a8ec6a735 to your computer and use it in GitHub Desktop.
Save alasvant/e74ce50a9f959212dcbce11a8ec6a735 to your computer and use it in GitHub Desktop.
Sample Episerver initialization module to fix Web API 2 attribute routing if other code has already called GlobalConfiguration.Configure without calling MapHttpAttributes().
using System.Web.Http;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
namespace AlloyFindWithWebApi.Business.Initialization
{
[InitializableModule]
[ModuleDependency(typeof(FrameworkAspNetInitialization))]
public class FixWebApiInitializationModule : IInitializableModule
{
public void Initialize(InitializationEngine context)
{
// register web api attributeroutes here
// this module is executed before EPiServer.Marketing.Testing initialization module because that module
// has dependency to EPiServer.Web.InitializationModule and this module uses FrameworkAspNetInitialization
// which is executed before the InitializationModule
// this is only needed in old marketing testing versions, issue has been fixed in version 2.5.11 at least
GlobalConfiguration.Configure(config =>
{
config.MapHttpAttributeRoutes();
});
}
public void Uninitialize(InitializationEngine context)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment