Skip to main content

Publish ASP.NET Core to IIS

Publishing DWD API, an ASP.NET Core 8.0 app, proved to be more complicated than previous iterations of .NET. This might have been due to the lack of HTML pages (unlike our other MVC projects that include HTML content), but ultimately I don't know why it was any different.

This document will list some of the extra steps taken when publishing the app.

Publish an ASP.NET Core app to IIS

ASP.NET Core Module (ANCM) for IIS

In-process hosting with IIS and ASP.NET Core

Configure and Publish the App

  1. Configure the publish profile:
    1. Right click on the project to be published and click on Publish....
    2. Select "to folder" as the publish method.
    3. Configure a custom publish location.
    4. Set Configuration to Release.
    5. Set Target Framework to net8.0, or whatever target framework is appropriate.
    6. Set Target Runtime to win-x64 (IIS is Windows only).
  2. IMPORTANT Set Deployment Mode to Framework-dependent.
  3. Publish the code.
  4. Zip the published code and transfer it to the machine with IIS (most likely using Sharepoint).

Configure IIS

  1. On the server machine, Install the .NET Core Hosting Bundle.
  2. Extract the zipped publish code to a directory on the server such as C:\dwd-api-aspnet\*
  3. Open IIS Manager.
  4. Create the IIS site
  5. The app pool should have been created automatically. If not, create it.
  6. Go to Advanced Settings for the app pool
    1. Set the .NET CLR Version to No Managed Code.
    2. Ensure IDentity is set to ApplicationPoolIdentity
  7. Right click the published code directory and go to Properties, Security, and add a security principal. For the targeted user, type in IIS AppPool\name-of-your-app-pool and click check names, before submitting. Give this security principal, ensure read and execute are allowed.
  8. In the published code directory, open the appsettings.json file and configure any database connections.
  9. In a terminal window, type iisreset.
  10. Test that you can access an endpoint for the site.

Configure HTTPS

Configuring HTTPS with a self-signed-certificate, while not secure, is quite easy in IIS.

How to Set Up SSL on IIS 7 or later

  1. Create the self-signed certificate:
    1. Open IIS Manager
    2. Select the server (the layer above app pools and sites)
    3. Double click on Server Certificates.
    4. In the right toolbar, select Create Self-Signed Certificate
    5. Enter a name for the cert and click OK.
  2. In IIS Manager, right click on the website and go to Edit Bindings.
  3. Add a new binding for HTTPS and select the newly created certificate.
  4. Submit the form.

Note that if you try to access this HTTPS URL from a browser, it will warn you that it's a potentially insecure website. You can click expand and proceed anyway to get past it.

REST calls shouldn't have any issues.