I have this (simplified) ASP.NET Core Web API controller. Both the GET and POST actions works nicely on my own machine. However, deployed to Azure only the GET action works properly. The POST action results in a 404. Any ideas?
namespace Foo
{
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
[RequireHttps]
[Produces("application/json")]
[Area("Foo")]
[Route("[area]/Api/[controller]")]
public class BarController : Controller
{
[HttpGet]
public IEnumerable<string> Get()
{
return new[] {"Hello", "World!"};
}
[HttpPost]
public void Post([FromBody] InputModel model)
{
}
public class InputModel
{
public int Foo { get; set; }
}
}
}
It is an ASP.NET Core MVC application targeting the full .NET framework. It is deployed as an Azure Web App. I have tested both actions on my local machine and in Azure using Postman.
It seems under certain circumstances when an error occurs in a controller, ASP.NET core returns 404 instead of a more appropriate 500. Check out this post:
ASP.NET Core 2.0 site POST request resulting in 404 on Azure
In the answer, it was caused by wrong database connection string (which may be a case when you publish an application to another environment), but it may be something else.
Not sure why it does not throw a normal error, maybe it tries to redirect to a custom error page or something like that.
To check this suggestion, try to remove everything from your POST controller to isolate a problem. If it won't return 404, it means that something in the controller throws an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With