I think this is missing from your
Application_Start
GlobalConfiguration.Configure(WebApiConfig.Register);
If I try
GlobalConfiguration.Configure(WebApiConfig.Register);
it means I have to move the configuration code to its own class, right?
I tried this:
public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Activate CORS config.EnableCors(); // Attribute routing config.MapHttpAttributeRoutes(); // Convention-based routing config.Routes.MapHttpRoute( name: "...", routeTemplate: "webapi/{controller}/{action}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ); } }
And adding
GlobalConfiguration.Configure(WebApiConfig.Register);
But it's still not working.
Seems weird that my own WebAPI stops working just because I upgrade EPiServer, adding 'EPiServer.Marketing.Testing 2.2.3''.
Without trying, I think it should look like this
// Enable Web API routing GlobalConfiguration.Configure(config => { WebApiConfig.Register(); // Activate CORS config.EnableCors(); // Attribute routing config.MapHttpAttributeRoutes(); // Convention-based routing config.Routes.MapHttpRoute( name: "ActionApi", routeTemplate: "webapi/{controller}/{action}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ); });
I managed to solve it by using the following code:
[InitializableModule] [ModuleDependency(typeof(EPiServer.Framework.FrameworkInitialization))] public class MyInitializationModule : IInitializableModule { public void Initialize(InitializationEngine context) { // Enable Web API routing GlobalConfiguration.Configure(config => { // Activate CORS config.EnableCors(); // Attribute routing config.MapHttpAttributeRoutes(); // Convention-based routing config.Routes.MapHttpRoute( name: "ActionApi", routeTemplate: "webapi/{controller}/{action}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } ); }); } }
Try removing config.MapHttpAttributeRoutes(); in your WebApiConfiguration.Register - ServiceAPI already calls this
I had removed MapHttpAttributeRoutes as well but got the following message even when I add
config.EnsureInitialized();
to the config file and initialize module
The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is
called in the application's startup code after all other initialization code.
I already add this line to Application_Start , but got same message:
GlobalConfiguration.Configuration.EnsureInitialized();
Adding this line to web.config fix the problem:
<add key="episerver:serviceapi:maphttpattributeroutes" value="false" />
Hi!
After doing a test upgrade to the very latest EPiServer version, along with 'EPiServer.Marketing.Testing 2.2.3', I'm now facing the following error when calling my own Web API:
The object has not yet been initialized. Ensure that HttpConfiguration.EnsureInitialized() is called in the application's startup code after all other initialization code.
Does anyone have a way of resolving this issue?
The start of my Global.asax.cs looks like this:
I've tried adding GlobalConfiguration.Configuration.EnsureInitialized(); to a couple of places but it still won't work.
Thanks in advance!