Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Web api in episerver doesn't work in iis

Vote:
 

Hi!

I have a web api in my EPiServer application which previously worked fine. But suddenly I can't get it to run in IIS. Localhost works fine. It seems the web api is found, but the routing is wrong. I get this error message in postman when I run (...)/api/epi/helptexts:

{
"Message": "No HTTP resource was found that matches the request URI '(...)/api/epi/helptexts'.",
"MessageDetail": "No type was found that matches the controller named 'helptexts'."
}

This is the controller:

[RoutePrefix("api/epi")]
public class ContentController : ApiController
{
[HttpGet]
[Route("helptexts")]
[AllowAnonymous]
public HttpResponseMessage GetHelptextsNorwegian()

This is the webApiConfig.cs:

[InitializableModule]
  [ModuleDependency(typeof(FrameworkInitialization))]
  public class WebApiConfig : IInitializableModule
  {

 public void Initialize(InitializationEngine context)
    {
      GlobalConfiguration.Configure(config =>
      {
        config.MapHttpAttributeRoutes();
        config.EnableCors();

        var formatters = GlobalConfiguration.Configuration.Formatters;
        var jsonFormatter = formatters.JsonFormatter;
        var settings = jsonFormatter.SerializerSettings;

        var enumConverter = new Newtonsoft.Json.Converters.StringEnumConverter();
        jsonFormatter.SerializerSettings.Converters.Add(enumConverter);

        settings.Formatting = Formatting.Indented;

        config.Formatters.Remove(config.Formatters.XmlFormatter);

        config.Routes.MapHttpRoute(
          name: "DefaultEpiApi",
          routeTemplate: "api/epi/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional });
      });
    }

This configuration works fine in another site. Can anyone point me in the right direction?

#197628
Oct 09, 2018 9:26
Vote:
 

I finally figured it out. I had to upgrade the .net framework from 4.5 to 4.6. I have no idea why, because everything was working fine before.

#197647
Oct 09, 2018 13:54
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.