Skip to content

Allow specifying host and port or port in ASPNETCORE_URLS #43135

Closed
@davidfowl

Description

@davidfowl

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Today ASP.NET Core allows specifying the scheme (http/https), host and port via a URL like syntax in ASPNETCORE_URLS and via the IServerAddressesFeature. This issue suggests we expand that the syntax supported to make it a bit more intuitive as this is a common production and container scenario. We want to make it more intuitive to specify the host and port or just the port to use for ASP.NET CORE applications. We can also take the opportunity to revisit what this new syntax would mean with respect to what the defaults are when pieces are unspecified.

Note: * and + are hold overs from HTTP.sys that we support on Kestrel as well but it's not obvious to most users (in fact + and * mean different things with HTTP.sys but not with Kestrel). I'm not sure if 0.0.0.0 work with HTTP.sys.

Describe the solution you'd like

When specifying the URL, we should support the following syntax:

  • {host}:{port} - Scheme = http, The host and port are specified
  • :{port} or {port} = Scheme = http, host = bind to all addresses (the equivalent of + or * today), port specified.

e.g.

via code

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World");

app.Urls.Add("8080"); // 8080 and all addresses
app.Urls.Add(":8081"); // 8081 and all addresses 
app.Urls.Add("localhost:8082"); // 8082 and localhost
app.Urls.Add("http://+:80"); // 80 and all addresses

app.Run();
ASPNETCORE_URLS=:8080;8081;localhost:5000;http://+:80

Open questions:

  • Do we listen on IPV6Any (::) or IPV4Any (0.0.0.0) by default? We should mimic the behavior or + and * today.
  • If the port is specified as 443, do we infer https? I think no, if you want TLS, specify the full URL including the scheme, host and port.
  • Do we support this with HTTP.sys? Yes we should pick if this syntax means * or +.
  • When this syntax is specified in code or via configuration what happens when you read IServerAddressesFeature.Addresses? These should return the processed urls.
  • Do we make a breaking change to rename Urls to Addresses on WebApplicationBuilder? No.
  • Should we rename url to address in WebApplicatiion.Run? Yes we can consider it as its much less of a breaking change.
  • Do we rename ASPNETCORE_URLS to ASPNETCORE_ADDRESSES? No. The value is too low.

Golang supports this syntax with their Listen API https://pkg.go.dev/net#Listen (the address portion).
nodejs defaults to listening on all addresses when the host is omitted.

Additional context

See dotnet/dotnet-docker#3968 for some background on this but it's been discussed in the past.

cc @richlander

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions