Section 2 of 6
IIS Hosting
🎯 What You'll Learn
- ASP.NET Core Module
- Installing .NET Hosting Bundle
- Publishing for IIS
- Creating IIS site
- web.config
ASP.NET Core Module
The ASP.NET Core Module is an IIS module that allows IIS to host ASP.NET Core applications by forwarding requests to Kestrel.
Install .NET Hosting Bundle
Download and Install
PowerShell
# Download from: https://dotnet.microsoft.com/download/dotnet
# Install .NET Hosting Bundle
# Restart IIS
net stop was /y
net start w3svc
Publish Application
Publish
Bash
dotnet publish -c Release -o C:\inetpub\wwwroot\InvenTrack
Create IIS Site
- Open IIS Manager
- Right-click Sites → Add Website
- Set Site name: InvenTrack
- Set Physical path: C:\inetpub\wwwroot\InvenTrack
- Set Binding: http, port 80
- Click OK
Application Pool Configuration
- Select Application Pools
- Right-click your app pool → Basic Settings
- Set .NET CLR version: No Managed Code
- Click OK
Important
ASP.NET Core apps run in a separate process, so set .NET CLR version to No Managed Code.
web.config
The publish process creates a web.config file automatically.
web.config
XML
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*"
modules="AspNetCoreModuleV2"
resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet"
arguments=".\InvenTrack.dll"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Hosting Models
| Model | Description | Performance |
|---|---|---|
| In-process | Runs inside IIS worker process | Faster |
| Out-of-process | IIS forwards to Kestrel | Slower |
Enable Logging
web.config (Enable Logs)
XML
<aspNetCore processPath="dotnet"
arguments=".\InvenTrack.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
</environmentVariables>
</aspNetCore>
Troubleshooting
- 500.19 Error: Check web.config syntax
- 500.30 Error: Application failed to start, check logs
- 502.5 Error: Process failure, check .NET version
- Enable logs: Set stdoutLogEnabled="true"
- Check Event Viewer: Application logs
Key Takeaways
- ASP.NET Core Module: IIS module for hosting
- Hosting Bundle: Install on server
- dotnet publish: Publish to IIS directory
- No Managed Code: Set in Application Pool
- web.config: Auto-generated configuration
- In-process: Faster hosting model