asp.net-core-webapivisual-studio-2022iis-10

Make .Net Core Web API deployed on IIS to work with Port 80


I created a Web API in using .Net Core 3.1 using VS 2022

Nothing fancy this is just the bare bones API that we get using the template with the Weather controller to which I added Swagger. Everything works fine from VS -> IIS Express.

Tried deploying to IIS locally on my development system.

Did not work.

First is the forbidden page when browsing from IIS:

enter image description here

And then tried accessing swagger:

enter image description here

Publish Settings from VS

enter image description here

In IIS: enter image description here

Did not change the defaults in Manage Application they are set to port 80 for Http and 443 to Https.

Out of curiosity I ran the executable from the publish folder, took the URL from there. This worked and the swagger page is displayed. enter image description here

So either it's the port or something else that I am not able to figure out. Appreciate any clues and guidance to make this work.

Thanks in advance.


Solution

  • Below are the steps to publish the ASP.NET Core Web API on IIS server:

    1. Open a project in Visual Studio, right-click on it and choose Publish option

    2. Choose the folder option and select a target folder and publish it

    3. Open the IIS server, right-click on the server name, and select Add Website...

    4. Enter website name, select path, and enter a port number -> click ok

    enter image description here

    1. Open Application Pools, double click on you web API application pool name

    2. From the .NET CLR version select No Managed Code

    enter image description here

    1. Install ASP.NET Core Hosting Bundle

    2. Add the below code in the Program.cs file:

    if (app.Environment.IsDevelopment()|| app.Environment.IsProduction())

    enter image description here

    enter image description here