I'm using ASP.NET Core. There are questions/answers on Stackoverflow related to developing with custom URLs already, but my situation seems to be a little different, as I need both https support and a custom base URL. I'm authorizing with a 3rd party with OAuth redirect flow. The 3rd party only supports redirect URLs that are https but not localhost. Right out of the box, Visual Studio 2017 (version 15.7.2) configured https support, which was a nice surprise. By default, my app launches on https://localhost:44348/
.
launchSettings.json
looks like this:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53837",
"sslPort": 44348
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyProject.Web": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
I've added a host entry to map a custom url to 127.0.0.1
127.0.0.1 app.mysite.local
...but I'm not able to access my site at https://app.mysite.local:44348/
. I get a Bad Request - Invalid Hostname
error.
I've tried changing this entry in .vs/config/applicationhost.config
from:
<binding protocol="https" bindingInformation="*:44348:localhost" />
to
<binding protocol="https" bindingInformation="*:44348:*" />
but then my app won't run at all, even if I run Visual Studio as an Administrator. Visual Studio shows this dialog:
I've even tried using the UseUrls()
extension method on IWebHostBuilder
:
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("https://*:44348/");
}
...but none of those techniques seem to work. Can anyone shed some light on how to get a custom base URL to work on https when developing ASP.NET Core apps?