UseHttpsRedirection does not respect runtime changes to Kestrel's endpoint configurations.
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Describe the bug
`UseHttpsRedirection` doesn't redirect to the current Kestrel port bound when changing it's configuration **at runtime via appsettings.json**. If the server was set to use `http://+:5000; https://+:5001` and then you modify the configuration for https to `https://+:6001` ; Kestrel will bind to the newly changed port and allow **https* traffic only if you go directly to the **https** endpoint. Trying **http** traffic will cause the response header `location` to have the old `https://+:5001` url, preventing redirection.
### To Reproduce
Clone this [repository](https://github.com/leo-costa/aspbug2) and run the app. You will see the default response on https from weatherforecast controller. **While the app is running**, change appsetting's Kestrel section to something like this and save it:
```
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5000"
},
"Https": {
"Url": "https://localhost:6000"
}
}
}
```
You can instantly go to port 6000 and the response returns, without ever restarting the app. Trying to use port 5000 on http will **not** redirect to port 6000.
### Further technical details
```
ASP NET Core 6.0 and 5.0
```
```
dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.100-preview.6.21355.2
Commit: 7f8e0d76c0
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\
Host (useful for support):
Version: 6.0.0-preview.6.21352.12
Commit: 770d630b28
.NET SDKs installed:
5.0.301 [C:\Program Files\dotnet\sdk]
6.0.100-preview.6.21355.2 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0-preview.6.21355.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-preview.6.21352.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-preview.6.21353.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```
```
Visual Studio 16.10.3
```
Contributor guide
Assessment
This issue has not been assessed yet.