Try our conversational search powered by Generative AI!

Can't get Web API 2 to work


Trying to get Web API working but I'm just getting 404s no matter what I do.

// Global.asax


// WebApiConfig.cs

public static void Register(HttpConfiguration config)

// ApiController in directory /ApiControllers

public class RequestPasswordController : ApiController
  public HttpResponseMessage Get()
    return Request.CreateResponse(HttpStatusCode.OK);

// Request is localhost:37001/api/requestpassword GET


Any ideas? I'm all out...

Dec 05, 2013 11:44

Looks like the route is empty?

e.g.: [Route("customers/{customerId}/orders")]


Dec 05, 2013 15:46

Having similar issue. Any Solution for this?

Oct 17, 2014 13:55

And a little bump. Had it working, then after a conflict it stopped working. Did you find out what the problem was?

Apr 07, 2015 15:01

A restart of VS and suddenly it worked again....

Apr 07, 2015 15:18

Which version of .Net are you using?

Apr 08, 2015 22:02

I don't know if this is the issue but if you are using System.Web.Mvc.RoutePrefix and System.Web.Mvc.Route instead of System.Web.Http.RoutePrefix System.Web.Http.Route the routes will not be registered for your ApiControllers. So, check your attributes and then it should work just fine.


Apr 09, 2015 23:18

Like Marcus is saying, it is important to add routes the right way, that is descibed in the linked document

This adds a normal default route

routes.MapRoute(name: "api", url: "api/{controller}/{action}", defaults: new { controller = "Login", action = "index" });

and this adds a default route for webapi

routes.MapHttpRoute(name: "API Default",routeTemplate: "webapi/{controller}/{id}",defaults: new { id = RouteParameter.Optional });
Apr 10, 2015 7:40

ok, my 2 cents ;) We discovered in our projects, that 4.5.1 and episerver and webapi somehow didn't play well together.. routing was not working

Apr 10, 2015 7:51

Interesting Valdis, we are using WebApi2 in a 8.1 project with MVC5 and it seems to work fine

Apr 10, 2015 8:17

We're using .NET 4.5.1. I switched to IIS Express and it started working, then switched back to regular IIS and it worked. A bit spooky, but I'm happy... :)

Apr 10, 2015 8:52

Erik, originally - when you where on IIS with 4.5.1 - it didn't work? You switched to express, then back - and it started to work?

Apr 10, 2015 9:43

Valdis, it worked first. But "suddenly" it stopped working (TFS conflicts, EPiServer updates etc). When switching to IIS Express and started to work, and switching back it worked again. Still havent figured out what the problem was, and I will not try to unless it happens again. :) Haven't changed .NET Framework during the process.

Apr 10, 2015 9:49

I've had a similar problem - I wanted to extend the new ServiceAPI with my own additional services - and added them using attribute routing - and no matter what I did, it simply wouldn't work...

Then, after updating my project to .NET 4.5.2 it started working all of a sudden (before it was 4.5.1). If it's the updated .NET or just the included reboot and restart that made it work I don't know.

Apr 15, 2015 14:11

Hi Henrik

In your second route registration, do you intentionally exclude the "action" from the template? Is there any specific reason?



Feb 16, 2016 11:35
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.