RezwanKhan-0288 avatar image
0 Votes"
RezwanKhan-0288 asked RezwanKhan-0288 commented

Web Api Returning 4040

I am getting a 404 from a .net core 5.0 web app that I have deployed to a newly set up windows server.

I have installed the dotnet-hosting-5.0.11-win runtime libraries on the server and installed IIS with the following settings:

IIS Settings

When I browse to it from IIS I get a 404. I gave up on the initial project and started clean with a stripped down version from the VS2019 templates. Still got the 404 :

404 Error145603-404.jpg

Here is the project from VS2019 itself just to give you a clearer idea of what I am trying to install and run from the Windows server:

VS2019 project

Here are the publish options for the project:

Publish Options

Created a new website in IIS for this app. Here are the settings for that:

IIS Website Settings

Here are the app pool settings for the app:

App pool settings

Here is the web.config file for the app:


Enabled directory browsing based on other posts I read:

Here is a snapshot of the logs file on the server:

Server Log Files

Any help appreciated!

iis-settings.jpg (126.1 KiB)
404.jpg (108.6 KiB)
projecttype.jpg (47.3 KiB)
publishoptions.jpg (52.7 KiB)
apppoolsettings.jpg (170.4 KiB)
webconfig.jpg (107.5 KiB)
logs.jpg (240.2 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Did you try adding the address to Trusted Sites (according to instructions shown in your 404.jpg image)?

0 Votes 0 ·

Yes tried that as you can see from the image:


0 Votes 0 ·
trusted-site.jpg (79.6 KiB)

1 Answer

BruceZhang-MSFT avatar image
0 Votes"
BruceZhang-MSFT answered RezwanKhan-0288 commented

Hi @RezwanKhan-0288 ,

I have reproduced the issue. It was caused by this code in startup file.

 if (env.IsDevelopment())
                 app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication1 v1"));

It only works when environment is development. So you need to add this in web.config.

     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />

The full element structure is

 <aspNetCore processPath="dotnet" arguments=".\TestWebApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
     <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />

Then you can access it well.

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Best regards,
Bruce Zhang

1.jpg (164.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The solution worked perfectly. Thanks so much!

0 Votes 0 ·