Try our conversational search powered by Generative AI!

EPiServer Marketing Testing Tools is breaking my site

Vote:
 

I have a site that uses a lot of webapi 2 within it and now we wanted to try out the EPiServer Marketing Testing Tools.

The installations worked great but suddently all my web api pages stopped working and giving me the 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 rememberd to have had this problem before when we were trying out Episerver Service Api so I identified it to be how we initialize our routes that do not work with how you are initialize your web api routes.

We do it in global.asax with override of RegisterRoutes and in application_start like this:

            GlobalConfiguration.Configuration.MapHttpAttributeRoutes();

            GlobalConfiguration.Configuration.Routes.MapHttpRoute(
                name: "[OURAPICALLNAME]",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional });


            GlobalConfiguration.Configuration.EnsureInitialized();

How should I change this to make it work with the new Marketing Testing Tools?

#175213
Feb 15, 2017 9:21
Vote:
 

Hi Henrik

I am not sure of the exact answer to your question but I think the Marketing tools makes use of the interceptor feature as described here: http://world.episerver.com/documentation/Release-Notes/ReleaseNote/?releaseNoteId=CMS-3603 and here: http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Initialization/dependency-injection/ and it sounds like it could be intercepting your WebAPI requests too? I could be completely wrong of course!

You could try registering your routes in an Episerver init module and ensuring it executes after the Marketing Testing tools init module EPiServer.Marketing.Testing.Web.Initializers.PublishContentEventListener this will ensure the code you supplied does at least execute after anything the Marketing Testing tools has done.

David

#175279
Feb 15, 2017 17:00
Vote:
 

Hi David,

I know how to write initialization modules but how would one write to code to ensure that it runs AFTER the marketing testing tools? Or after any other module?

Currently experiencing the same problems as Henrik frown

#178080
Apr 28, 2017 15:56
Vote:
 

Hi Marcus

You can use the Episerver Debugging tools to look for all init modules: https://www.david-tec.com/2015/02/episerver-debugging-tools/ and look for the marketing testing init module.

Then add a dependency on the Marketing testing init module using the following:

[ModuleDependency(typeof([Name of Marketing testing module]))]

David

#178115
May 02, 2017 13:06
Vote:
 

Thanks for the link to the EPiServer Debugging tools - a hidden gem!

I managed to solve my problems 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 }
			);
		});
	}
}

I took dependency on EPiServer.Framework.FrameworkInitialization instead of EPiServer.Web.InitializationModule.

#178126
Edited, May 02, 2017 15:46
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.