0

I am having an issue when trying to publish a Web API running on .NET 5 on Azure I keep getting a 404 error

Even the default ASP.NET Core Web API template is failing when deployed to Azure.

I already set Azure to use early access on .NET 5 and I even tried self-contained deployment.

Ignore the fact the screenshot is accessing index.html, that was just a test, same happens accessing the routes of any actions in the controllers.

Any ideas?

5
  • Sorry to break this to you, but WebAPI's don't have HTML pages. They only have controllers. If you want to have documentation pop up, I would get Swagger, then you can go to https://example.com/swagger and see your controllers: learn.microsoft.com/en-us/aspnet/core/tutorials/… If you want a web site with HTML content, then don't choose the WebAPI option when creating your project. Commented Feb 18, 2021 at 1:06
  • hehe, yeah I know, posted the wrong screenshot, that is not the issue it happened even with the default route, no static files. Turns out Azure requires you to have an additional wwwroot folder with js, and cs, even if you have a Web API that is supposed to have no static files Commented Feb 18, 2021 at 2:09
  • 1
    I've been writing WebAPIs in Azure for 4 years and have never had to have any wwwroot directory or any static content what-so-ever. The default WebAPI project in Visual Studio 2019 is all you need. Commented Feb 18, 2021 at 2:26
  • Neither did I, until I released this specific project in .NET 5. Default Web API projects on .NET Core 3.1 are deploying just fine. Commented Feb 18, 2021 at 2:31
  • Turns out Azure required me to add an additional wwwroot with js, and css files, even when my project is configured to use endpoints only Never heard of requiring this additional wwwroot folder for API project on Azure. Commented Feb 18, 2021 at 2:39

3 Answers 3

2

Please note that the API template is a project template for creating a RESTful HTTP service, as @Andy mentioned, WebAPI project usually does not serving HTML pages.

If you really want to serve a index.html page in your WebAPI project, you can try:

1)create a wwwroot folder in your project and put index.html within it

enter image description here

2)call the UseStaticFiles method in Startup.Configure, which enables static files to be served

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    //...
    //your code here...

    app.UseHttpsRedirection();

    app.UseStaticFiles();

    app.UseRouting();

    //...

For more information about serving static files, please check:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-5.0

it happened even with the default route, no static files.

You can try to access your API endpoint with your actual route that you configured, that might look like below.

https://xxx.azurewebsites.net/api/{controller_name}/{action_name?}

Or

https://xxx.azurewebsites.net/{controller_name}/{action_name?}
Sign up to request clarification or add additional context in comments.

Comments

0

So, I was able to fix the issue. I compare to other project I had deployed in the past and to a Blazor in .NET 5 I have deployed too. Turns out Azure required me to add an additional wwwroot with js, and css files, even when my project is configured to use endpoints only, and is not using static files at all.

Comments

0

As of yesterday the issue is not happening anymore

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.