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:
dotnet publish --configuration Release
Directory Browsing
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:
dotnet run
, I can call the endpoints successfullyMultiple questions pop in my head:
Is there anything else that should be configured?
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.