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

System Environment Variables not being read on server #1864

Closed
Allann opened this Issue Dec 7, 2016 · 8 comments

Comments

Projects
None yet
5 participants
@Allann
Copy link

Allann commented Dec 7, 2016

I have an asp.net core website which works fine locally. I use environment variables to store the Environment and a couple of connection strings. Not a problem locally. When i deploy the website to the server (via release manager, xcopy and powershell scripts running as an administrator) the appropriate variables are created/updated on that server. I have confirmed that they are there.

I start the website and I get the following returned in the log:

Hosting environment: Production
Content root path: d:\apps\FreightRates
Now listening on: http://localhost:9657
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://auqldrv00dev1si:10000/  

So it is starting, but the environment is being reported as Production. Don't know where that is coming from because the ASPNETCORE_Environment=DEV. I don't use the term "Production" anywhere in my code, I have dbl-checked. We use the term "PRD". I even updated the default template code to use UAT,PRD instead of Staging, Production in all the places it appears (_Layout.cshtml, etc).

I have raised a stackoverflow question outlining in more detail the issue.

I appears that the system environment variables are being completely ignored. I thought initially that it may be a permission issue, but I changed the Application Pool in IIS to run as me, but still not.

Can anyone point me in a direction to look for the issue? Or that I can respond to to further clarify the setup.

@davidfowl

This comment has been minimized.

Copy link
Member

davidfowl commented Dec 7, 2016

It might be useful to dump all environment variables in your app

@Allann

This comment has been minimized.

Copy link
Author

Allann commented Dec 7, 2016

i did a SET command from a command prompt on that server to confirm that the variables existed and where set correctly. They were.

@davidfowl

This comment has been minimized.

Copy link
Member

davidfowl commented Dec 7, 2016

@Allann I mean writing code in the application itself that dumps the environment variables.

@Tratcher

This comment has been minimized.

Copy link
Member

Tratcher commented Dec 7, 2016

IIS doesn't pick up environment variable changes without restarting the service or machine. Note Production is the default value.

@davidfowl

This comment has been minimized.

Copy link
Member

davidfowl commented Dec 7, 2016

You shouldn't have to restart the machine to see new env vars. Recycling the application pool should be enough.

@Allann

This comment has been minimized.

Copy link
Author

Allann commented Dec 7, 2016

I just noticed that the ApplicationPool instance had LoadUserProfile =false, setting it to true made the site work as expected and the variables were loaded. Now to change the deployment script that creates the apppool to ensure that value is set to true.

I was a little surprised I had to load the user profile for machine variables.

Thanks for the help.

@Allann Allann closed this Dec 7, 2016

@smiller781

This comment has been minimized.

Copy link

smiller781 commented Jan 4, 2018

Mine has LoadUserProfile = true. Still not working.

@kakins

This comment has been minimized.

Copy link

kakins commented Feb 21, 2018

Setting LoadUserProfile = true worked for me also. Is there any documentation for this?

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