Skip to content

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

DamianEdwards
Copy link
Member

@DamianEdwards DamianEdwards commented Jul 7, 2025

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 for localhost, allowing for infinite variations on the host name while maintaining the benefits of the localhost address. An ASP.NET Core application started with an ASPNETCORE_URLS config value (or "applicationUrl" in launchSettings.json) will be resolvable on any address that binds to the loopback address, so a value of http://myapp.localhost:12345 will also be resolvable via http://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 the localhost address. In the case a .localhost address is being used, Kestrel will print out that it's listening on both the .localhost address, and regular localhost without the sub-domain prefix too so it's obvious that both are resolvable, e.g.:

image

The developer certificate logic had the certificate version incremented, and was updated to include new SANs for the following addresses:

  • *.localhost
  • *.internal

Fixes #62592

image

image

@github-actions github-actions bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jul 7, 2025
}
],
"shortName": "blazor",
"sourceName": "BlazorWeb-CSharp",
"sourceName": "BlazorWebCSharp.1",
Copy link
Member Author

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.

@lewing
Copy link
Member

lewing commented Jul 8, 2025

/azp run

Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@DamianEdwards
Copy link
Member Author

@lewing seems it's failing in main the same way

@lewing
Copy link
Member

lewing commented Jul 8, 2025

@lewing seems it's failing in main the same way

yeah I was hoping the windows images had been successfully rolled back by now, clearly they have not

@@ -19,8 +19,8 @@ namespace Microsoft.AspNetCore.Certificates.Generation;

internal abstract class CertificateManager
{
internal const int CurrentAspNetCoreCertificateVersion = 3;
internal const int CurrentMinimumAspNetCoreCertificateVersion = 3;
internal const int CurrentAspNetCoreCertificateVersion = 4;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do we need to increment this if we already did it for 10.0?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're shipping revision 3 in preview.6 so we need to increment again for preview.7 otherwise folks using the previews won't get the new certificate.

@DamianEdwards
Copy link
Member Author

@BrennanConroy addressed your feedback, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add *.localhost & *.internal to the dev cert SANs
3 participants