dotnet / dotnet/aspnetcore

Changing IHostingEnvironment.ApplicationName using ASPNETCORE_APPLICATIONNAME env variable

Open
#11,085 3 comments 8 reactions 0 assignees View on GitHub
affected-few area-hosting area-networking enhancement severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Currently it not possible to change IHostingEnvironment.ApplicationName property via environment variables.

Although the variable is correctly read in the WebHostBuilder class, it is overwritten in the UseStartup method.

https://github.com/aspnet/AspNetCore/blob/d24ec01224726fa85dc7683d0f70a94d9172bc94/src/Hosting/Hosting/src/WebHostBuilder.cs#L45
https://github.com/aspnet/AspNetCore/blob/d24ec01224726fa85dc7683d0f70a94d9172bc94/src/Hosting/Hosting/src/WebHostBuilderExtensions.cs#L75

### Describe the solution you'd like
Maybe this fix in UseStartup method will solve the problem:

```cs
public static IWebHostBuilder UseStartup(this IWebHostBuilder hostBuilder, Type startupType)
{
if (string.IsNullOrEmpty(hostBuilder.GetSetting(WebHostDefaults.ApplicationKey)))
{
var startupAssemblyName = startupType.GetTypeInfo().Assembly.GetName().Name;

hostBuilder.UseSetting(WebHostDefaults.ApplicationKey, startupAssemblyName);
}

// ...
}
```

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.