Reputation: 883
I am able to perform a web deploy to an Azure App Service successfully, but then the web application can't be found.
I deployed an ASP.NET Core 2.2 web application that works fine locally. On the portal, nothing is showing a problem. When I call it via e.g.,
https://xxxxxxxxx.azurewebsites.net/api/values
I get the error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. (404)
Upvotes: 8
Views: 7783
Reputation: 883
It turns out that Visual Studio 2019 does not create a web.config
file. That does not bother our on-premise IIS servers. But the Azure App Service needs one — but does not provide a specific error if it doesn’t have one.
I got the hint from they read, “.NET Core Web API not working after being deployed to Azure”.
None of the walkthroughs or tutorials I have seen mention it.
Upvotes: 0
Reputation: 782
If the deployment from VS was successful, first thing to test is the endpoint and if it serves the data you need.
In my case I was using .NetCore 3.0 with a fresh WebApi project. After deploying and navigating to the base URL
https://xxxxxxxxx.azurewebsites.net/api/values
https://xxxxxxxxx.azurewebsites.net/swagger/index.html
With this, take note of tomRedox answer where he recommends commenting out the if statement within configure method
//if (env.IsDevelopment())
//{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication6 v1"));
//}
I noticed that commenting this out does not automatically serve the swaggerUI upon deployment as it would in your localhost.
Upvotes: 2
Reputation: 30443
Another gotcha with API projects is that their UI (often their Swagger UI) may only be available during development, but not once they are deployed to live.
To check for this have a look in Startup.cs for any code that is run conditionally based on anenv.IsDevelopment()
check. For example, the .NET Core Web API template adds this code:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication6 v1"));
}
If you put that project's API URL in the browser on a development machine you'll see the Swagger API as expected. However, if you do the same with the deployed version of that app you'll get a 404 as env.IsDevelopment
is no longer true.
There are some other scenarios that can cause a 404 in this thread too.
Upvotes: 6
Reputation: 5294
The reason for this is that the deployment or default ASP.NET Core Web API template does not include a default document in the root directory of the web site. For example, index.htm, defualt.aspx, default.htm are default documents and IIS will deliver them if there is no specific file provided when accessing the URL.
You can place one of those files into the root directory of the web site, in the wwwroot
directory or request the ASP.NET Core Web API
directly by appending /api/<methodname>
or by default add api/values
to the end of your ASP.NET Core Web API and you should then get a JSON or XML response as expected.
Hope it helps.
Upvotes: 0