|
| 1 | +### Support for the .localhost Top-Level Domain |
| 2 | + |
| 3 | +The `.localhost` top-level domain (TLD) is defined in [RFC2606](https://www.rfc-editor.org/rfc/rfc2606) and [RFC6761](https://www.rfc-editor.org/rfc/rfc6761) as being reserved for testing purposes and available for users to use locally as they would any other domain name. This means using a name like `myapp.localhost` locally that resolves to the IP loopback address is allowed and expected according to these RFCs. Additionally, modern evergreen browsers already automatically resolve any `*.localhost` name to the IP loopback address (`127.0.0.1`/`::1`), effectively making them an alias for any service already being hosted at `localhost` on the local machine, i.e. any service responding to `http://localhost:6789` will also respond to `http://anything-here.localhost:6789`, assuming no further specific hostname verification or enforcement is being performed by the service. |
| 4 | + |
| 5 | +ASP.NET Core has been updated in .NET 10 preview 7 to better support the `.localhost` TLD, such that it can now be easily used when creating and running ASP.NET Core applications in your local development environment. Having different apps running locally be resolvable via different names allows for better separation of some domain-name-associated website assets, e.g. cookies, and makes it easier to identify which app you're browsing via the name displayed in the browser address bar. |
| 6 | + |
| 7 | +ASP.NET Core's built-in HTTP server, Kestrel, will now correctly treat any `*.locahost` name set via [supported endpoint configuration mechanisms](https://learn.microsoft.com/aspnet/core/fundamentals/servers/kestrel/endpoints#configure-endpoints) as the local loopback address and thus bind to it rather than all external address (i.e. bind to `127.0.0.1`/`::1` rather than `0.0.0.0`/`::`). This includes the `"applicationUrl"` property in [launch profiles configured in a *launchSettings.json* file](https://learn.microsoft.com/aspnet/core/fundamentals/environments#development-and-launchsettingsjson), and the `ASPNETCORE_URLS` environment variable. When configured to listen on a `.localhost` address, Kestrel will log an information message for both the `.localhost` **and** `localhost` addresses, to make it clear that both names can be used. |
| 8 | + |
| 9 | +*Note that while web browsers will automatically resolve `*.localhost` names to the local loopback address, other applications may treat `*.localhost` names as a regular domain names and attempt to resolve them via their corresponding DNS stack. If your DNS configuration does not resolve `*.localhost` names to an address then they will fail to connect. You can continue to use the regular `localhost` name to address your applications when not in a web browser.* |
| 10 | + |
| 11 | +The [ASP.NET Core HTTPS development certificate](https://learn.microsoft.com/aspnet/core/security/enforcing-ssl#trust-the-aspnet-core-https-development-certificate) (including the `dotnet dev-certs https` command) have been updated to ensure the certificate is valid for use with the `*.dev.localhost` domain name. After installing .NET 10 SDK preview 7, trust the new developer certificate by running `dotnet dev-certs https --trust` at the command line to ensure your system is configured to trust the new certificate. |
| 12 | + |
| 13 | +*Note that the certificate lists the `*.dev.localhost` name as a Subject Alternative Name (SAN) rather than `*.localhost` as it's invalid to have wildcard certificates for top-level domain names* |
| 14 | + |
| 15 | +The project templates for *ASP.NET Core Empty* (`web`) and *Blazor Web App* (`blazor`) have been updated with a new option that when specified configures the created project to use the `.dev.localhost` domain name suffix, combining it with the project name to allow the app to be browsed to at an address like `https://myapp.dev.localhost:5036`: |
| 16 | + |
| 17 | +``` |
| 18 | +$ dotnet new web -n MyApp --localhost-tld |
| 19 | +The template "ASP.NET Core Empty" was created successfully. |
| 20 | +
|
| 21 | +Processing post-creation actions... |
| 22 | +Restoring D:\src\MyApp\MyApp.csproj: |
| 23 | +Restore succeeded. |
| 24 | +
|
| 25 | +$ cd .\MyApp\ |
| 26 | +$ dotnet run --launch-profile https |
| 27 | +info: Microsoft.Hosting.Lifetime[14] |
| 28 | + Now listening on: https://myapp.dev.localhost:7099 |
| 29 | +info: Microsoft.Hosting.Lifetime[14] |
| 30 | + Now listening on: https://localhost:7099/ |
| 31 | +info: Microsoft.Hosting.Lifetime[14] |
| 32 | + Now listening on: http://myapp.dev.localhost:5036 |
| 33 | +info: Microsoft.Hosting.Lifetime[14] |
| 34 | + Now listening on: http://localhost:5036/ |
| 35 | +info: Microsoft.Hosting.Lifetime[0] |
| 36 | + Application started. Press Ctrl+C to shut down. |
| 37 | +info: Microsoft.Hosting.Lifetime[0] |
| 38 | + Hosting environment: Development |
| 39 | +info: Microsoft.Hosting.Lifetime[0] |
| 40 | + Content root path: D:\src\local\10.0.1xx\MyApp |
| 41 | +``` |
0 commit comments