Home > database >  How to host a DotNet Core 6.0 WebAPI project on IIS using CLI?
How to host a DotNet Core 6.0 WebAPI project on IIS using CLI?

Time:03-04

I am trying to host my webapi project locally using IIS server. I am using VS Code to create my webapi using .NET 6.0.

Here are the steps I took:

  1. I ran dotnet publish --configuration Release. This created files under 'bin\Release\net6.0'.
  2. I downloaded the ASP.NET Core 6.0 Runtime (v6.0.2) - Windows Hosting Bundle.
  3. Next, I created a website in IIS using the Physical Path as 'bin\Release\net6.0' and set the port to 8084.

Now when I try to browse to the path, localhost/8084/api/users it returns 500 Internal Server Error. What am I missing?

Settings for IIS

CodePudding user response:

I was able to find the solution go this, thanks to @gunr2171.

The issue was with using user-secrets. When using user-secrets, IIS is not able to find the secrets.json file. This caused the application at IIS to fail with null reference(Found this through Event Viewer).

A solution that I found to this is - for development purpose, we can copy paste the secrets.json file to the physical path being used by IIS to host. This lets us continue hosting through IIS without issues.

CodePudding user response:

You need to install this bundle, then try again :). Check your .net core version

  • Related