I think everyone agrees that using HTTPS for your web applications is the default. Therefore it makes sense to have the HttpsRedirection middleware always active in your ASP.NET Core application:
However when I tried to run this ASP.NET Core application using IIS Express, I always arrived at the root url of my local IIS instance(https://localhost/):
I found the source of this behaviour in the launchsettings.json file where I had only http configured:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"profiles": { | |
"IIS Express": { | |
"commandName": "IISExpress", | |
"launchBrowser": true, | |
"environmentVariables": { | |
"ASPNETCORE_ENVIRONMENT": "Development" | |
} | |
}, | |
"eShopExample": { | |
"commandName": "Project", | |
"launchBrowser": true, | |
"environmentVariables": { | |
"ASPNETCORE_ENVIRONMENT": "Development" | |
}, | |
"authenticationMode": "Windows", | |
"applicationUrl": "http://localhost:42441/" | |
} | |
}, | |
"iisSettings": { | |
"windowsAuthentication": true, | |
"anonymousAuthentication": false, | |
"iisExpress": { | |
"applicationUrl": "http://localhost:42440/" | |
} | |
} | |
} |
The https middleware causes the redirect to https but as there is no IIS Express https endpoint active I end up on https://localhost (and get the default IIS web page):
The solution is to active an https endpoint by specifying the sslPort
:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"profiles": { | |
"IIS Express": { | |
"commandName": "IISExpress", | |
"launchBrowser": true, | |
"environmentVariables": { | |
"ASPNETCORE_ENVIRONMENT": "Development" | |
} | |
}, | |
"eShopExample": { | |
"commandName": "Project", | |
"launchBrowser": true, | |
"environmentVariables": { | |
"ASPNETCORE_ENVIRONMENT": "Development" | |
}, | |
"authenticationMode": "Windows", | |
"applicationUrl": "http://localhost:42441/" | |
} | |
}, | |
"iisSettings": { | |
"windowsAuthentication": true, | |
"anonymousAuthentication": false, | |
"iisExpress": { | |
"applicationUrl": "http://localhost:42440/", | |
👇 | |
"sslPort": 44327 | |
} | |
} | |
} |