Search code examples
asp.net-coredeploymentswaggeriis-8windows-server-2012

Deploy a ASP.NET Core Web API with Swagger UI to Windows Server 2012 (IIS 8) that hosts several other websites


I have developed a simple Web API with ASP.NET Core 2.2, which has a Swagger UI (via Swashbuckle). I'll call it "my_api" here.

I am using Visual Studio 2017 on Windows 7 to develop.

This web app works well on my localhost while developing (of course).

http://localhost:5000/swagger

This URL will open the swagger UI.

http://localhost:5000/api/[endpoints]

These URL endpoints will retrieve various resources from the database.


What I want to achieve (not sure if this is possible):

I want to deploy this web app to a Windows Server 2012 running IIS 8, which already has three other relatively static websites running.

I want to deploy the build in a folder ("my_api_folder") in "wwwroot" on this server. Then:

http://www.server-domain.com/my_api_folder/swagger

will open the swagger UI.

http://www.server-domain.com/my_api_folder/api/[endpoints]

will invoke my various API endpoints.


What I have done:

I build (publish) the web app using VS 2017, to a folder.

I build it as a Self-Contained Deployment (SCD) hoping this will be easier to deploy.

The build target (RID) I am using is win-x64.

After the build process complete, I have one executable ("my_api.exe"), several dlls, and other assets/config files in the "publish" folder .Net Core generated.

I can run this executable on my local machine by double clicking it. It will listen on localhost:5000 and all work well.

Then I deploy (copy&paste) all the build files to the "my_api_folder" folder on the server.


The issues now I am facing:

After the deployment, both

http://www.server-domain.com/my_api_folder/swagger

and

http://www.server-domain.com/my_api_folder/api/[endpoints]

will return 500 Internal Server Error.

Then I try double clicking the executable on the server, it will run. (It shows listening on localhost:5000).

However, I cannot open http://localhost:5000/swagger (or http://127.0.0.1:5000/swagger) on the server, or call the API. (404 Not Found on the server's IE browser.)

I also cannot access those routes from outside of the server. But this time it hangs a long time and eventually shows the gateway is not responding.

But

netstat -a -o -n

shows "my_api.exe" is indeed listening on port 5000, after I ran the executable manually.


My description is probably everywhere. I am feeling that I am missing some key knowledge to make this work here.

Please advise how should I debug this?

What might be the causes?

If you need any additional info, please let me know too.

Thanks.


Solution

  • I think one can follow this documentation and adapt to its own situation: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1