Web API interface works locally but gets 404 after deployed to Azure Website

Felix Yao picture Felix Yao · Nov 16, 2012 · Viewed 7.8k times · Source

I'm working on a ASP.NET MVC 4 website. Together with MVC controllers, I have one API controller which contains an ajax GET API interface. It works perfectly when debugged locally with visual studio.

However, after I deployed it as an Azure Website, MVC controllers work, but the API controller doesn't work anymore. When jQuery code tries to reach it, it returns a response like:

No HTTP resource was found that matches the request URI 'http://example.com'.

It looks like at least the route works (otherwise, another 404 response body is returned.).

Additionally, I have another pure MVC 4 Web API service deployed as an Azure Cloud Service. It works perfectly. Thus, I wonder what causes the API inside MVC Website to fail? Thank you!

Answer

JohnT picture JohnT · Mar 12, 2020

We give a name to the controller via attribute based routing and a name to each of the endpoints inside the controller. Generic by convention GET, PUT, POST, PATCH are not allowed for security reasons.

Cybersecurity and our DevOps requires it for both firewall logs, performance monitoring and security monitoring.

Consider using:

    [Route("api/inventory")]
    public class InventoryController : ApiController
    {
      [HttpGet("inventorylist")]
      public IActionResult InventoryList() 
      { 
      }

      [HttpGet("inventoryitem")]
      public ActionResult InventoryItem([FromQuery] string itemId) 
      {
      }
    }