Try our conversational search powered by Generative AI!

Error get web api to work


Aftert installing EPiServer.CloudPlatform.Cms and the dependent package EPiServer.Cms.HealtCheck all my ApiControllers (web api) stopped working and I got his error. An important pice of information is that the web api's that got the error (se below) were set up this attribute routing!

ERROR: "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 have a webapiconfig.cs with a register method, where I call this:


And in Global.asax.cs I have this:


and also this in the end of Application_Start() in global.asax.cs:


My controller looks like this:

  public class MyApiController : ApiController
    public int test()
      return 42;

So attribute routing is set up using GlobalConfiguration.Configure.MapHttpAttributeRoutes(), and after some reflection of the EPiServer.Cms.HealthCheck packages I figured out that this module also were calling GlobalConfiguration.Configure.MapHttpAttributeRoutes(), but that it was possible to disalbe.

SOLUTION: A appSetting key kan be used to disable the extra call to MapHttpAttributeRoutes for the HealthCheck module

  <add key="episerver:healthcheck:maphttpattributeroutes" value="false" />

This is setting is not documented any place by Optimizely, that I can find...

Edited, Apr 12, 2023 19:39

Info: The service api has a similar appsettingskey for disabling the same thing:

Apr 12, 2023 19:41

The answer is inside the forum post;)

Apr 12, 2023 19:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.