listener port specified in appsetting.json file is not getting overridden by either ASPNETCORE_URLS or --urls options for asp.net core application
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
listener port mentioned in appsetting.json file is not getting overridden by either ASPNETCORE_URLS or --urls
### Expected Behavior
Our asp.net core application is launched by another parent application as part of it we need to provide a mechanism for parent application to override default address and port specified in appsettings.json file of our asp.net core application . And as per documentation it says we can override the default port in appsetting.json file either using the environment variable "ASPNETCORE_URLS" or command switch "--urls" and their priority order of override as below ( from highest to lowest)
1 ) Command-Line Arguments (--urls)
2 ) Environment Variables (ASPNETCORE_URLS)
3) Code Configuration (e.g., UseKestrel() in Program.cs)
4) appsettings.json
but what I observed is default address and port takes highest priority even after setting other ways i.e. command line / env variable .
### Steps To Reproduce
1. Create a sample asp.net core razer application using VS IDE 2022
2. Update appsettings.json file as below
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information"
}
},
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:5000"
}
}
}
}
3. set environment variable "set ASPNETCORE_URLS=http://*:5001"
4. and run the application dotnet dynamic.port.dll --urls "http://*:5002"
**Actual behavior**
- Either environment variable or command line options does not override the default address and port.
### Exceptions (if any)
_No response_
### .NET Version
8.0.400
### Anything else?
dotnet dynamic.port.dll --urls "http://localhost:5002"
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
User profile is available. Using 'C:\Users\xxxxx\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: E:\Prasad\RandD\Dotnet-ServiceApps\dynamic.port\bin\Debug\net8.0\wwwroot. Static files may be unavailable.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Overriding address(es) 'http://localhost:5002'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: E:\Prasad\RandD\Dotnet-ServiceApps\dynamic.port\bin\Debug\net8.0
Contributor guide
Assessment
This issue has not been assessed yet.