Share via

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

P. G. Choudhury 141 Reputation points
Feb 9, 2025, 1:37 PM

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].

ASP.NET (C#)
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,788 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.
33 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 71,591 Reputation points
    Feb 11, 2025, 4:50 PM

    your error middleware should log the exception, so you can determine why. say unable to connect to database, etc.

    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Jalpa Panchal-MSFT 795 Reputation points Microsoft Vendor
    Feb 11, 2025, 9:41 AM

    @P. G. Choudhury , so now i tried with the scalar. i just used simple comtroller:

    ASP.NET (C#)
    using Microsoft.AspNetCore.Authorization;
    using Microsoft.AspNetCore.Mvc;
    namespace ScalarApiDemo.Controllers
    {
        [Route("api/[controller]")]
        [ApiController]
        public class PlayerController : Controller
        {
            private static readonly string[] Players = new[]
            {
                "Player1", "Player2", "Player3", "Player4"
            };
            [HttpGet("GetAllPlayers")]
            public IActionResult GetAllPlayers()
            {
                return Ok(Players);
            }
        }
    }
    

    and when i tried to access with the [http://localhost:8730/api/Player] i got same result 404.User's image

    after the test i found the correct url is: /api/Player/GetAllPlayers

    User's image

    User's image

    let me know if there is still some misunderstanding.

    Best Regards,

    Jalpa


    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.

    1 person found this answer helpful.
    0 comments No comments

  2. AgaveJoe 29,866 Reputation points
    Feb 9, 2025, 4:39 PM

    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...

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

    To this...

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

    Or this...

    YAML
    // 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.


  3. Bruce (SqlWork.com) 71,591 Reputation points
    Feb 9, 2025, 4:49 PM

    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)


  4. 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.