dotnet / dotnet/AspNetCore.Docs

Dynamic port binding solution does not make sense to me

Open
#31,861 2 comments 0 reactions 1 assignee Claimed by @tdykstra View on GitHub
aspnet-core/svc doc-bug fundamentals/subsvc Source - Docs.ms
Dominant language
C#
Stars
13.1k
Forks
24.6k
Avg merge
1d 3h
Merged PRs (30d)
97

Description

***EDIT by @Rick-Anderson***

[Dynamic port binding](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-8.0#dynamic-port-binding)

End of @Rick-Anderson edit

### Description

The documentation (https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-8.0#dynamic-port-binding) suggests to use `app.Run(async (context) => { ...})` which does not make sense to me.

This is setting up a request delegate as a middleware!? Do I miss something or is the proposed solution incorrect or incomplete? Trying the solution makes the app terminate immediately.

I'd rather see this as a proposed solution:

```cs
app.Start ();

var server = app.Services.GetRequiredService ();
var serverAddressFeature = server.Features.Get ();

if (serverAddressFeature is not null)
{
var listenAddresses = string.Join(", ", serverAddressFeature.Addresses);

// ...
}
```

### Page URL

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-8.0

### Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/fundamentals/servers/kestrel/endpoints.md

### Document ID

fd9cc0c2-3ea3-f437-e0ac-8789fb96faf7

### Article author

@tdykstra

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.