Sarah
Sarah

Reputation: 1293

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()

Upvotes: 4

Views: 3740

Answers (2)

T-CROC
T-CROC

Reputation: 76

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.

Upvotes: 3

Sarah
Sarah

Reputation: 1293

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

Upvotes: 1

Related Questions