title: web api 2 area routes
body: <p>I am using asp.net mvc 5 and web api 2.   For the asp.net mvc 5 project I have everything working... but new I am trying to add web api 2 routes... when I am using areas.</p>
  
  <p>I have the web api 2 controller working at the project root:</p>
  
  <pre><code> //this is working 
     namespace EtracsWeb.Controllers
      {
          public class TestController : ApiController
          {
              //localhost:port/api/test ...this is working
              [HttpGet]
              public HttpResponseMessage Get()
              {
  
                  return new HttpResponseMessage()
                  {
                      Content = new StringContent("GET: Test message")
                  };
              }
  
          }
      }
  </code></pre>
  
  <p>So I am assuming my <code>Global.asax</code>, my <code>routeconfig.cs</code> and my <code>webapiconfig.cs</code> are correct ... (not shown)...</p>
  
  <p>But now I am trying to get the web api 2 in my AREAS working...</p>
  
  <p>I have read everything I could find on the web and this seems like it should 
  work:</p>
  
  <pre><code>namespace EtracsWeb.Areas.WorkOrder
  {
      public class WorkOrderAreaRegistration : AreaRegistration
      {
          public override string AreaName
          {
              get
              {
                  return "WorkOrder";
              }
          }
  
          public override void RegisterArea(AreaRegistrationContext context)
          {
  
              context.Routes.MapHttpRoute(
                      name: "AuditModel_Api",
                      routeTemplate: "WorkOrder/api/AuditModelApi/{id}",
                      defaults: new { id = RouteParameter.Optional }
                  );
  
          //default
              context.Routes.MapHttpRoute(
                      name: "WorkOrder_Api",
                      routeTemplate: "WorkOrder/api/{controller}/{id}",
                      defaults: new { id = RouteParameter.Optional }
                  );
  
              context.MapRoute(
                   "WorkOrder_default",
                  "WorkOrder/{controller}/{action}/{id}",
                  new { action = "Index", id = UrlParameter.Optional }
              );
          }
      }
  }
  </code></pre>
  
  <p>My controller code is:</p>
  
  <pre><code>namespace EtracsWeb.Areas.WorkOrder.ApiControllers
  {
      public class AuditModelApiController : ApiController
      {
          IManufacturerStopOrderModelService auditModelService = new WorkOrder.Services.VWAuditModelService(UserSession.EtracsUserID, UserSession.ProgramID, UserSession.EtracsSessionID, UserSession.ConnectionString);
  
          [HttpGet]
          [Route("AuditModelApi")]
          public HttpResponseMessage Get()
          {
  
              return new HttpResponseMessage()
              {
                  Content = new StringContent("GET: Test message")
              };
          }
  
          [Route("AuditModelApi/AuditModels")]
          public IEnumerable&lt;VwAuditModel1&gt; GetAuditModels()
          {
                  return auditModelService.GetModels();
          }
  
          public IHttpActionResult UpdateAuditMode()
          {
              //example of what can be returned ... NotFound, Ok ... look into uses...
  
              VwAuditModel1 result = new VwAuditModel1();
              return Ok(result);
  
              return NotFound();
          }
      }
  }
  </code></pre>
  
  <p>I have tried the controller with and without the attribute naming <code>[Route]</code>...
  and I can't get either get to work...</p>
  
  <p>Both the simple case</p>
  
  <pre><code>    public HttpResponseMessage Get()
  </code></pre>
  
  <p>and the "real" case </p>
  
  <pre><code>  public IEnumerable&lt;VwAuditModel1&gt; GetAuditModels()
  </code></pre>
  
  <p>return the same result. From the browser, using </p>
  
  <pre><code>http://localhost:64167/WorkOrder/api/AuditModelApi
  </code></pre>
  
  <p>and</p>
  
  <pre><code>http://localhost:64167/WorkOrder/api/AuditModelApi/AuditModels
  </code></pre>
  
  <p>I get the following:</p>
  
  <pre><code>&lt;Error&gt;
  &lt;Message&gt;
  No HTTP resource was found that matches the request URI 'http://localhost:64167/WorkOrder/api/AuditModelApi/AuditModels'.
  &lt;/Message&gt;
  &lt;MessageDetail&gt;
  No route providing a controller name was found to match request URI 'http://localhost:64167/WorkOrder/api/AuditModelApi/AuditModels'
  &lt;/MessageDetail&gt;
  &lt;/Error&gt;
  </code></pre>