Created
January 12, 2020 13:01
-
-
Save alasvant/a62fdc9db7c5deca58b66d04ad5019ab to your computer and use it in GitHub Desktop.
Sample Episerver initialization module to add convention based Web API routes in an Add-On
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Http; | |
using EPiServer.Framework; | |
using EPiServer.Framework.Initialization; | |
namespace AlloyFindWithWebApi.Business.Initialization | |
{ | |
[InitializableModule] | |
[ModuleDependency(typeof(EPiServer.Web.InitializationModule))] | |
public class ApiHttpRoutesInitializationModule : IInitializableModule | |
{ | |
public void Initialize(InitializationEngine context) | |
{ | |
// get the HttpConfiguration and then add our "custom" routes to the Routes collection | |
var httpConfig = GlobalConfiguration.Configuration; | |
httpConfig.Routes.MapHttpRoute( | |
"CustomWebApiRouteTemplate", | |
routeTemplate: "custom-api/{controller}/{id}", | |
defaults: new { id = RouteParameter.Optional } | |
); | |
// use the httpConfig instance to register other routes as you need | |
} | |
public void Uninitialize(InitializationEngine context) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment