tomab
tomab

Reputation: 2151

.NET Core Web API not working after being deployed to Azure

I have a simple .NET Core Web API application—the one made by Visual Studio when a new project is created. I want to deploy it to an Azure App Service via FTP as part of a Team Foundation Server (TFS) 2017 build job, which is successful:

enter image description here

However, when trying a GET request such as the following URL:

http://somerandomname.azurewebsites.net/api/values

All I get is a 404 with the text:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

From Kudu, I get the following error:

enter image description here

What am I missing?

Upvotes: 6

Views: 13175

Answers (3)

Asad
Asad

Reputation: 93

I had the same issue with the .net 5 API project. It works fine on local machine but after publishing to Azure WebApp it gives the error

This ****.azurewebsites.net page can’t be found

In my case following lines were missing from Startup.cs

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            }
        );

Adding these lines in the configuration section of the startup.cs fixed the issue.

Upvotes: 0

Kirsten
Kirsten

Reputation: 18076

I had a similar problem using Azure DevOps.

I decided to try publishing by right click deploy to a different app service, so that I could see what web.config I should have.

The right click deployed app did show /api/values where as the devops app did not.

The only difference in the web.configs were the location of stdoutLogFile

Using right click deploy

stdoutLogFile="\\?\%home%\LogFiles\stdout"  

Using devops

stdoutLogFile=".\logs\stdout

However right click deploy had included all my 3rd party dlls, so I am thinking somehow my devops pipeline nuget settings need correcting.

I am asking about that here

Upvotes: 2

tomab
tomab

Reputation: 2151

So a web.config is needed. The one which VS 2017 populates with some default values when a new item is added it's not good. Using a VS 2017 web api default project, I've published it using right-click menu. That worked seamlessly. I've took the web.config from Azure web service and integrated it in my own project, changing only the dll name. Now, when a build job is running on behalf of TFS, it has the web.config among the files which are uploaded via FTP to Azure app service.

Here is the web.config I've ended with:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
  <remove name="aspNetCore"/>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
  <aspNetCore processPath="dotnet" arguments=".\Somerandomname.WebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>

Upvotes: 6

Related Questions