Reeves62
Reeves62

Reputation: 149

Web app http 404 error in azure but runs locally

I am trying to create a web api that connects to my Azure SQL database and reads from the data, I used the 'API' template from VS19 and adding my own files, I ran the app locally (the templates weather forecast worked fine) and I tested my API using postman. I then deployed my api directly from VS to my app service in Azure but when I go to the URL I get the following error:

This securedmessaging.azurewebsites.net page can’t be foundNo web page was found for the web address: https://****.azurewebsites.net/ HTTP ERROR 404

Can someone please help me run the app from azure as it runs locally? Im not sure where I went wrong. Below is a picture of my solution explorer.

enter image description here

Upvotes: 8

Views: 10504

Answers (2)

Asad
Asad

Reputation: 93

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

Fei Han
Fei Han

Reputation: 27825

web page was found for the web address: https://securedmessaging.azurewebsites.net/ HTTP ERROR 404

You mentioned that the app is a ASP.NET Core Web API app that does not include and serve a default page, so that it would cause a 404 Not Found error while you access the site without a fully qualified URI.

To make request to API endpoint, you can try:

https://securedmessaging.azurewebsites.net/WeatherForecast 

Or

https://securedmessaging.azurewebsites.net/api/brokers/{action_name_here}

Besides, if you'd like to serve a default page that's displayed at the root URL for a website, you can try:

1) Create Default.html under wwwroot folder

enter image description here

2)Call the UseDefaultFiles method in Configure method of Startup.cs

app.UseDefaultFiles();

app.UseStaticFiles();

app.UseRouting();

Test Result

enter image description here

Upvotes: 6

Related Questions