'Azure Web API giving a 404 when deployed but works locally

We have a .NET Core Web API deployed as an Azure Web App. All endpoint work locally, however, once deployed, we have one controller that is gives us a 404 for all endpoint we hit within it.

We have checked and triple checked that the url we are calling is correct & from what we can tell, there is nothing different about this controller relative to the others in our application.

This is our BinController that is giving us 404's:

namespace API.Controllers
{
    [Route("api/[controller]")]
    [Authorize]
    [ApiController]
    public class BinController : ControllerBase
    {
        private readonly IBinRepository _binRepo;
        private readonly ILogger _logger;

        public BinController(IBinRepository binRepo, ILogger<BinController> logger)
        {
            _binRepo = binRepo;
            _logger = logger;
        }

        [HttpGet("{locationId}/{binId}")]
        public async Task<IActionResult> CheckBinExists(int locationId, string binId)
        {
            try
            {
                bool result = await _binRepo.CheckBinExists(locationId, binId);
                return Ok(result);
            }
            catch (Exception e)
            {
                return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
            }
        }

        [HttpGet("findAll/{locationId}/{itemId}")]
        public async Task<IActionResult> FindAllBinsWithItem(int locationId, string itemId)
        {
            try
            {
                var result = await _binRepo.FindAllBinsWithItem(locationId, itemId);
                return Ok(result);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
            }
        }

        [HttpGet("contents/{locationId}/{bin}")]
        public async Task<IActionResult> GetBinContents(int locationId, string bin)
        {
            try
            {
                List<BatchLine> contents = await _binRepo.GetBinContents(locationId, bin);
                return Ok(contents);
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
            }
        }
    }
}

We are calling https://ourapiname.azurewebsites.net/api/Bin/1234/TestBin.

To Summarize:

  • All endpoints work locally
  • All controllers work when deployed except for one
  • We have multiple other controllers in our application with similar if not the same setup, but this one is returning a 404 when deployed

We saw these similar posts, but they did not resolve this issue:

I wish I could provide more insight, but we are really at a loss for what could be going on here. Any ideas would be greatly appreciated.



Solution 1:[1]

This does not make any sense, but I simply changed the name of the Controller from "BinController" to "BinsController" and now it works...

Must not be able to name a controller "Bin".

Solution 2:[2]

You can deploy your web project with Self-Contained mode, then find the project_name.exe and double-click it. Test it in your local, and your test url should be https://localhost:5001/api/Bin/1234/TestBin.

If you can run it works well in your local, the second step you should to create a new webapp, then deploy it as usual. We just rult out the some specifical reason in your original webapp.?like: deploy failed?

If it still not work, my suggestion is you can manually drag and drop the publish file to the kudu site of the azure webapp.


The steps above should be useful to you, but I think the easiest way is to go to the kudu site to get the dll file, and then decompile it, so that the root cause of the problem can be found.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BryceBy
Solution 2 Jason