dotnet / dotnet/aspnetcore

Application Initialization Module does not work if SSL Required = true in IIS Manager

Open
#25,287 6 comments 1 reaction 0 assignees View on GitHub
affected-very-few area-networking bug investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Describe the bug
When an ASP.NET Core application is set to preload in IIS the application starts immediately when an application pool starts or recycles. However, if the application is _also_ configured in IIS Manager to require SSL then the application initialization feature stops working. When the application pool is started or recycled the application is **not** started immediately. Instead IIS waits for an incoming request before loading the application.

### To Reproduce
Create any ASP.NET Core project, e.g. a basic MVC site using the VS template. Add some logging during application startup so you can clearly see when the application started without hitting any application endpoints. For example, in the Program.Main method write a timestamp to a log file:

`System.IO.File.AppendAllText(@"C:\Temp\mvc-log.txt", $"Main: {DateTime.Now}\n");
`

Publish the application to IIS. Grant your application pool user (or everyone) write access to the folder you're logging to (e.g. c:\temp). When you hit the site you should see a message written to the log file.

In IIS Manager configure the application to auto-start by updating the application pool and application settings as described in the documentation: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#application-initialization-module. Close any browser windows that have the site open.

Every time you recycle the application pool you should see another message added to the log file indicating that the application is starting immediately (without waiting for you to browse to the site).

Now go back to IIS Manager, navigate to the ASP.NET Core application and open the SSL Settings feature. Check "Require SSL" and press apply. Application preload is now broken. If you recycle the application pool the application no longer starts immediately. Nothing is written to the log after a recycle -- until you hit the site again in a browser window.

### Exceptions (if any)
None.

### Further technical details

.NET Core SDK (reflecting any global.json):
Version: 3.1.401
Commit: 5b6f5e5005

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.401\

Host (useful for support):
Version: 3.1.7
Commit: fcfdef8d6b

.NET Core SDKs installed:
3.1.200 [C:\Program Files\dotnet\sdk]
3.1.201 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]
3.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.