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.
Useful Links
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
- Configure the publish profile:
- Right click on the project to be published and click on
Publish.... - Select "to folder" as the publish method.
- Configure a custom publish location.
- Set Configuration to
Release. - Set Target Framework to
net8.0, or whatever target framework is appropriate. - Set Target Runtime to
win-x64(IIS is Windows only).
- Right click on the project to be published and click on
- IMPORTANT Set Deployment Mode to
Framework-dependent. - Publish the code.
- Zip the published code and transfer it to the machine with IIS (most likely using Sharepoint).
Configure IIS
- On the server machine, Install the .NET Core Hosting Bundle.
- Extract the zipped publish code to a directory on the server such as
C:\dwd-api-aspnet\* - Open IIS Manager.
- Create the IIS site
- The app pool should have been created automatically. If not, create it.
- Go to Advanced Settings for the app pool
- Set the .NET CLR Version to No Managed Code.
- Ensure IDentity is set to ApplicationPoolIdentity
- 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-pooland click check names, before submitting. Give this security principal, ensure read and execute are allowed. - In the published code directory, open the
appsettings.jsonfile and configure any database connections. - In a terminal window, type
iisreset. - 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
- Create the self-signed certificate:
- Open IIS Manager
- Select the server (the layer above app pools and sites)
- Double click on
Server Certificates. - In the right toolbar, select
Create Self-Signed Certificate - Enter a name for the cert and click OK.
- In IIS Manager, right click on the website and go to Edit Bindings.
- Add a new binding for HTTPS and select the newly created certificate.
- 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.