-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Support *.localhost TLD for local dev #62593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -166,6 +166,11 @@ static string ExpandPorts(string ports, string scheme) | |||
foreach (var address in addresses) | |||
{ | |||
Log.ListeningOnAddress(LifetimeLogger, address); | |||
if (address.Contains(".localhost") && Uri.TryCreate(address, UriKind.Absolute, out var uri) && uri.Host.EndsWith(".localhost", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the check for contains first to avoid extra Uri
allocations.
} | ||
], | ||
"shortName": "blazor", | ||
"sourceName": "BlazorWeb-CSharp", | ||
"sourceName": "BlazorWebCSharp.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was required in order to support all the default value forms for the sourceName
in accordance with the docs for sourceName
. Specifically, we want to use the lower case class name
form for the value of "applicationUrl"
in the launchSettings.json file.
Support *.localhost TLD for local dev
Description
This PR adds support to ASP.NET Core for local dev with a
*.localhost
address, i.e. an address using the.localhost
TLD.The
.localhost
TLD is always resolved to the localhost loopback address in modern browsers without any DNS configuration required (as per RFC 6761). It's effectively an alias forlocalhost
, allowing for infinite variations on the host name while maintaining the benefits of the localhost address. An ASP.NET Core application started with anASPNETCORE_URLS
config value (or"applicationUrl"
in launchSettings.json) will be resolvable on any address that binds to the loopback address, so a value ofhttp://myapp.localhost:12345
will also be resolvable viahttp://localhost:12345
. Note that non-browser scenarios should continue to use the plain localhost address as they rely on regular DNS configuration to resolve a.localhost
TLD address to the loopback address.The empty and blazor web templates have been updated with a new option,
--localhost-tld
, that can be specified to opt the new project into using the.localhost
TLD for the application URL. The other templates focusing on non-browser scenarios or using parts of ASP.NET Core not considered our primary, modern, recommended approach, have not been updated but users are free to manually change their launch profiles to use the.localhost
TLD.Kestrel itself was updated to treat
.localhost
addresses the same as thelocalhost
address. In the case a.localhost
address is being used, Kestrel will print out that it's listening on both the.localhost
address, and regularlocalhost
without the sub-domain prefix too so it's obvious that both are resolvable, e.g.:The developer certificate logic had the certificate version incremented, and was updated to include new SANs for the following addresses:
*.localhost
*.internal
Fixes #62592