New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.net core 2.2 appends the environment variable value from web.config file and from user's system #6140

Closed
Eilon opened this Issue Dec 27, 2018 · 10 comments

Comments

Projects
None yet
7 participants
@Eilon
Copy link
Member

Eilon commented Dec 27, 2018

From @jsowndarrajan on Wednesday, 26 December 2018 07:17:54

Issue Title

Environment variable in web.config file get appended into system environment variable

General

Recently, I'm facing a strange issue while hosting .net core 2.2 application on IIS.

After hosting, I get "An error occurred while starting the application". In order to identify the root cause I enabled the log file and found that its because of environment variable issue.

I configured the environment variable in my web.config file as like below, at the same time I also configured the same (ASPNETCORE_ENVIRONMENT) environment variable in my system.

<aspNetCore processPath="dotnet" arguments=".\PctrClient.Api.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
    <environmentVariables>
      <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
    </environmentVariables>
  </aspNetCore>

But when I try to host this application in IIS, I get ASPNETCORE_ENVIRONMENT variable value as Development;Development, instead of Development. I think, application is now appending both system environment value and web.config variable value together.

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
               .UseStartup<Startup>()
               .UseIISIntegration();
}

From my perceptive, web.config should override the system environment variable value.

Please let me know if you need any other information from my end.

Copied from original issue: dotnet/core#2184

@Eilon

This comment has been minimized.

Copy link
Member Author

Eilon commented Dec 27, 2018

From @karelz on Wednesday, 26 December 2018 19:51:54

I think the behavior is fairly reasonable. You need to decide what to use - env vars or config file, not both.
I let ASP.NET experts to make final decision though.

@Eilon

This comment has been minimized.

Copy link
Member Author

Eilon commented Dec 27, 2018

This behavior does look by-design to me. @Tratcher do you have additional thoughts?

@jsowndarrajan

This comment has been minimized.

Copy link

jsowndarrajan commented Dec 27, 2018

Hi Ellison, Thanks for the response. From my perspective we have to check web.config first, if the env variable present there we can use it, otherwise we have to check system level configuration.

But right now we are reading the value from both places and more importantly we are concatenate those value. I think it's strange behavior.

I don't know the actual intention behind appending the env values?!

If it's working as per the design, is there any plan to change it in the future releases?

@Tratcher

This comment has been minimized.

Copy link
Member

Tratcher commented Dec 27, 2018

@shirhatti @pakrym @jkotalik

It's a toss up, different environment variables want different semantics. E.g. for PATH you'd want to append (or prepend?), but for ASPNETCORE_ENVIRONMENT you'd want to replace. It seems like the environmentVariable config node should let you specify the behavior.

@pakrym

This comment has been minimized.

Copy link
Member

pakrym commented Dec 27, 2018

Dup #4566 we even have PR #6083

I think we should just override in most cases. Overriding path seems fine if customer decided to do it.

@Tratcher

This comment has been minimized.

Copy link
Member

Tratcher commented Dec 27, 2018

Does it support nesting so they can append manually? E.g. "{PATH};c:\mypath"

@pakrym

This comment has been minimized.

Copy link
Member

pakrym commented Dec 27, 2018

I'll add tests, it should. "%PATH%;c:\mypath"

@Eilon Eilon removed their assignment Dec 28, 2018

@pakrym pakrym self-assigned this Dec 29, 2018

@shirhatti

This comment has been minimized.

Copy link
Member

shirhatti commented Jan 2, 2019

@guardrex Can we have this behavior added to the docs? I believe this would be the appropriate section- https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2#setting-environment-variables

@guardrex

This comment has been minimized.

Copy link
Contributor

guardrex commented Jan 2, 2019

@shirhatti 👍 I'll get that scheduled.

@alexlchen

This comment has been minimized.

Copy link

alexlchen commented Jan 13, 2019

I have the same issue. When I changed the environment variable value from "Development" to "Staging" or "Product", The error happened and showed "HTTP Error 500.30 - ANCM In-Process Start Failure".
After I set it back to "Development", everything is ok.
LaunchSetting.json
{
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Product"
}
}
},
}

Note:
I did the same setting at .Net Core 2.0, everything is good.
There must be a bug with .Net Core 2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment