Web Api Returning 4040

Rezwan Khan 21 Reputation points
2021-11-01T20:25:18.847+00:00

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:

Web.Config

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!

Internet Information Services
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,252 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,113 questions
{count} votes

Accepted answer
  1. Bruce Zhang-MSFT 3,736 Reputation points
    2021-11-02T03:08:37.653+00:00

    Hi @Rezwan Khan ,

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

    if (env.IsDevelopment())  
                {  
                    app.UseDeveloperExceptionPage();  
                    app.UseSwagger();  
                    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.

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

    The full element structure is

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

    Then you can access it well.
    145646-1.jpg


    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


0 additional answers

Sort by: Most helpful