'Deploying dotnetcore 5 web api to iis gives 404
I have an Web API project with .NET 5 (created directly from the template of visual studio Asp.NET Core Web API), it works just fine when debugging from Visual studio, tried to deploy it to IIS server, which has the Hosting Bundle of .NET 5 installed, the deployment apparently runs fine, but when I enter the url I have a 404. Have a separate MVC .NET 5 project, which I deploy in the same way and it runs perfectly fine.
Would like to know if someone can point me to the right direction, can't find what I'm missing here.
Solution 1:[1]
Faced the same issue. After configuring, when tried to browse 404 error came up.
The reason is, Swagger page will be configured in only for development environment as below(in Startup.cs).
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AppName v1"));
}
The APIs will be available if we type in the correct url. If you still wants to view the Swagger file
Either change the code in startup.cs remove the check for
if (env.IsDevelopment())
Or In your web.config file set environment as Development.
Solution 2:[2]
If you have deployed a NET5 API to local IIS for development propose, you should set the environment to development using the web.config file
<aspNetCore processPath="dotnet" arguments=".\NewDealerWebAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore
Solution 3:[3]
You can solve your problem by following the steps on this site.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ajith |
Solution 2 | Osley Hernández Calvo |
Solution 3 | Hasan Batuhan Kurt |