Deploying an ASP.NET Core Application to IIS

What is IIS Deployment?

Internet Information Services (IIS) is a web server developed by Microsoft. Deploying your ASP.NET Core application to IIS allows you to host it on a Windows server for public or private access.

  • Reliable Hosting: IIS is widely used for hosting .NET applications.
  • Built-in Support: ASP.NET Core is compatible with IIS using the Kestrel server.
  • Secure: Leverages Windows security features for secure deployment.

Why Deploy to IIS?

Deploying to IIS is ideal for hosting internal business applications or public-facing websites in a Windows environment.


Step-by-Step Guide to Deploy ASP.NET Core to IIS

Follow these steps:

1. Install the .NET Core Hosting Bundle


// Download and install the hosting bundle from:
// https://dotnet.microsoft.com/en-us/download/dotnet

                

The hosting bundle includes the ASP.NET Core Module, which allows IIS to work with Kestrel.

2. Publish Your Application


// Run the following command in the terminal:
dotnet publish -c Release -o ./publish

                

This generates a folder with the compiled files needed for deployment in the publish directory.

3. Configure IIS

  • Open the IIS Manager (inetmgr).
  • Right-click on Sites and choose Add Website.
  • Enter the Site Name, choose the Physical Path (your published files), and set a Port (e.g., 5000).

Physical Path: C:\Path\To\Publish\Folder
Port: 5000

                

4. Configure Application Pool

  • In IIS Manager, go to Application Pools.
  • Find your application’s pool, right-click, and select Basic Settings.
  • Set the .NET CLR version to No Managed Code (ASP.NET Core uses Kestrel).

5. Test Your Application


// Access your application in the browser:
http://localhost:5000

                

Ensure that the application runs correctly and check the IIS logs for any errors.

6. Optional: Enable HTTPS

  • In IIS Manager, select your site and click Bindings.
  • Add an HTTPS binding and associate it with a certificate (e.g., self-signed or purchased).

7. Configure Web.config


// Add or update the Web.config file in your published folder
<configuration>
  <system.webServer>
    <aspNetCore processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

                

This ensures IIS knows how to start your application.