localhosthosting.net-6.0iis-10windows-server-2019

ASP.NET Core 6 Web API & IIS 10 - Not Found


I am trying to deploy my ASP.NET Core 6 Web API on IIS on a Windows Server 2019 machine. The end goal is to only call my API on localhost:port/swagger or localhost:port/{controller}/{action} from that server (and not from the outside).

Here is what I have so far:

  1. Published the API using the following command: dotnet publish --configuration Release
  2. I have Microsoft .NET 6.0.14 - Windows Server Hosting installed
  3. I have enabled Directory Browsing
  4. I added a new site in IIS, and pointed the physical path to a folder where I pasted the published output:
  5. Configured the binding to http, IP address Àll Unassigned, and port 8080`

When I click on Browse, it takes me to the URL localhost:8080, and I get the list of files that are in the physical path, which is correct.

If I try to use localhost:8080/swagger, I get a 404, if I use localhost:8080/{controller}/{getaction}, I also get a 404.

What I have done so far to troubleshoot:

  1. I made sure that my IIS USER has access to that folder
  2. I have ran the executable in the folder, and the API works fine
  3. If I run the API with dotnet run, I can call the endpoints successfully
  4. I have read if any particular configuration should be done in the code, but it didn`t seem like it

Multiple questions pop in my head:

  1. Is there some configuration that I should be doing in the code?
  2. How is IIS supposed to run my application? Does it run the executable? Is it looking for something that isn't there? etc.
  3. Is there a configuration that I missed in IIS?
  4. Is IIS looking for an executable, a DLL?
  5. How does IIS identify which is the main DLL?

Is there anything else that should be configured?


Solution

  • After wasting a lot of time trying to understand what was happening, I created a new Web API, the default generated template containing the Forecast controller. I tried creating a site in IIS for that, like I did for my API, and it worked. After comparing the configuration of both projects, I finally found the issue.

    For some reason, in my csproj, I had the following:

    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PlatformTarget>x64</PlatformTarget>
    

    In addition, my project's output type was exe instead of Console application.

    This resulted in generating a publish folder that didn't contain the main DLL; it contained only the exe application and a couple of other files. When I changed the configuration to match the newly generated API, the publish folder had the same structure as the one generated for the Forecast API.

    After doing that, I successfully accessed my website through IIS, loaded the swagger page, and sent requests.