.NetCore 9.0 webAPI published and deployed to IIS gives HTTP Error 404 upon browsing -

P. G. Choudhury 121 Reputation points
2025-02-09T13:37:24.01+00:00

Hello,

I need some pointers reg. this scenario I am about to describe. I created a .NetCore 9.0 WebAPI and published it to my IIS. My installed IIS version is 10 (v10.0.19041.1). I created separate Application Pool setting the CLR Version to 'No Managed Code' and Pipeline Mode 'Integrated'. I published my webAPI from Visual Studio 2022 using 'Folder Profile' and consequently proceeded to add my webAPI under 'Sites' following usual steps.

Problem is, if I 'Browse' my newly added webAPI it gives me a blank page with the following error. Whereas it should be opening a Scalar Documentation page[since I used Scalar in my project].

This localhost page can’t be found
No webpage was found for the web address: http://localhost:****/
HTTP ERROR 404

However if I browse to http://localhost:****/weatherforecast it opens the following:
1_1

In my project there's a Player webapi controller. So when I try to open http://localhost:****/api/player it again opens the error page as such:
1_2

Be informed that, I have enabled Directory Browsing for the published WebAPI on my IIS. I have also enabled Default Document for it although I haven't "set/attached" any file like index.html with it. Can you guess what exactly could be wrong with my scenario? Let me mention one more funny thing, if I click on 'Browse' for the 'DefaultWebSite' it doesn't open the default welcome page of IIS instead lists the directories. Is my IIS Installation corrupted? Hoping not!

That's least of my concerns. I want to know, what needs to be done so that Scalar Documentation page opens when I 'Browse' my configured 9.0 webAPI. Give me some hints.

Thanks,

Internet Information Services
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,776 questions
ASP.NET Core Training
ASP.NET Core Training
ASP.NET Core: A set of technologies in the .NET Framework for building web applications and XML web services.Training: Instruction to develop new skills.
32 questions
{count} votes

3 answers

Sort by: Most helpful
  1. AgaveJoe 29,776 Reputation points
    2025-02-09T16:39:04.84+00:00

    Can you guess what exactly could be wrong with my scenario? Let me mention one more funny thing, if I click on 'Browse' for the 'DefaultWebSite' it doesn't open the default welcome page of IIS instead lists the directories. Is my IIS Installation corrupted? Hoping not!

    That's expected since you enabled Directory Browsing and you are using a browser to navigate a Web API which does not have a user interface.

    That's least of my concerns. I want to know, what needs to be done so that Scalar Documentation page opens when I 'Browse' my configured 9.0 webAPI. Give me some hints.

    What do you expect to see? If you are expecting Open API then make sure your configuration is setup to show Open API outside the development environment.

    Change this...

    // Configure the HTTP request pipeline.
    if (app.Environment.IsDevelopment())
    {
        app.UseSwagger();
        app.UseSwaggerUI();
    }
    
    
    

    To this...

        app.UseSwagger();
        app.UseSwaggerUI();
    

    Or this...

    // Configure the HTTP request pipeline.
    if (app.Environment.IsDevelopment())
    {
        app.MapOpenApi();
    }
    

    To this...

    app.MapOpenApi();
    

    If you are expecting a default API action then set the expected action or controller as the root route. See the official docs.

    https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/routing?view=aspnetcore-9.0

    If you are expecting something else then explain what you are trying to do.


  2. Bruce (SqlWork.com) 71,101 Reputation points
    2025-02-09T16:49:06.41+00:00

    You don’t specify which OpenAI (swagger) library you are using or if you included one. Unless you configured to be the default route, typically you need to include the OpenAI route. (/swagger)


  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.