Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure endpoint reached, but calls to API returning 404 error

We have set up an app service project in the Azure Portal and then went through deployment of the project using Visual Studio DevOps. When I go to http://MyAzureSite.azurewebsites.net (Made up URL here), I can confirm that the service is up and running.

But when I add "api/ControllerName/getStatus", I get a 404 error.

Call from my local machine is working perfectly fine.

http://localhost:52686/api/status/getStatus

But not:

http://MyAzureSite.azurewebsites.net/api/status/getstatus

Signature for the GetStatus looks good:

[HttpGet]
public List<Status> GetStatus()
like image 901
Sarah Avatar asked Oct 19 '25 05:10

Sarah


2 Answers

We had the same exact problem with the most recent .NET Core 3.1 LTS release. We found multiple things that can cause this problem. Here are our findings:

  1. API endpoints should extend ControllerBase instead of Controller:

API Controller extending ControllerBase

ControllerBase creates a controller WITHOUT view support. Controller is for view support. We had an API endpoint that couldn't be reached when deployed in Azure if it was extending Controller and it didn't have a view. No errors or anything. Just couldn't reach it.

  1. Make sure the App Service is configured for the correct stack. Our web API uses .NET Core 3.1. If you create it from Visual Studio, it may be configured for the incorrect stack. Our Visual Studio 2019 configured it for 3.0 EOL by default. When we changed it to 3.1, things worked again.

Azure Portal Configuration

  1. Creating from Azure Portal doesn't work with default configuration.

If you create the App Service / Web App through the Azure Portal, you won't be able to reach any of the endpoints at first. We are not sure why this is, but we figured out how to make it work again. Go to the configuration for the App Service and follow these steps:

  1. Turn Off "Always On"
  2. Save and wait for settings to apply
  3. Turn On "Always On"
  4. Save and wait for settings to apply

Number Labeled Configuration Steps

Now you should be able to hit your API endpoints again

These were a few problems that we had and the solutions to them. Hopefully, they help you guys out and save you from days of going "We fixed it!" just to have it stop working again for another unknown reason. I'll update this answer as I find more things that break APIs and App Services and as I find solutions to them.

like image 179
T-CROC Avatar answered Oct 21 '25 22:10

T-CROC


We had to rebuild the project properly again, its the way project was created that was incorreect.

like image 37
Sarah Avatar answered Oct 21 '25 21:10

Sarah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!