dotnet / dotnet/aspnetcore

DOTNET_URLS ignored by Kestrel on macOS / .NET Core 3.1 + .NET 5 Preview 8

Open
#25,273 16 comments 0 reactions 0 assignees View on GitHub
affected-very-few area-networking enhancement severity-nice-to-have
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

On macOS with both .NET Core 3.1 + .NET 5 Preview 8, Kestrel ignores the `DOTNET_URLS` environment variable.

Funnily, using the `URLS` environment variable **does** work, but this shouldn't be the case because the host configuration environment variables use the `DOTNET_` prefix by default. My ASP.NET Core knowledge is quite limited, but after playing around with `ConfigureHostConfiguration` and `ConfigureAppConfiguration`, it seems that Kestrel reads the URLs from the app configuration instead of the host configuration.

### Steps to reproduce

- Go into a new empty directory (macOS! Haven't tried Windows.)
- `dotnet new web`
- Verify SDK version with `dotnet --info` (5.0.0-preview.8.20407.11)
- `DOTNET_URLS=http://localhost:4567 dotnet run`

**Output:**

```
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
```

Commands that **do work**:

- `URLS=http://localhost:4567 dotnet run`
- `dotnet run --urls http://localhost:4567`

**Output:**

```
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:4567
```

### Code generated by "dotnet new web" in the steps to reproduce

Nothing special.

```
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
});
}
```

### Further technical details

```
.NET SDK (reflecting any global.json):
Version: 5.0.100-preview.8.20417.9
Commit: fc62663a35

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/5.0.100-preview.8.20417.9/

Host (useful for support):
Version: 5.0.0-preview.8.20407.11
Commit: bf456654f9
```

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.