Skip to content
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

different paths for system with ASPNETCORE_ENVIRONMENT set and without it #124

Closed
jimmyca15 opened this issue Aug 9, 2017 · 8 comments
Closed
Labels

Comments

@jimmyca15
Copy link
Member

@kae @drago-draganov I moved the issue that was created at the bottom of #59 to here.

https://github.com/Microsoft/IIS.Administration/blob/dev/src/Microsoft.IIS.Administration/ConfigurationHelper.cs#L21

            RootPath = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") != null ?
                       Directory.GetCurrentDirectory() : Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

This code gets different paths for system with ASPNETCORE_ENVIRONMENT set and without it

So on development servers it's going to get default service directory and throw exception of not finding config directory.

Is there any sensible reason for not just using Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) on all systems?

@jimmyca15
Copy link
Member Author

The code was added because the application structure has some differences between when we develop and when we run it in production (non-development).

Are you setting the ASPNETCORE_ENVIRONMENT variable system wide on your development servers and if so what value are you using?

@kae
Copy link

kae commented Aug 9, 2017

@jimmyca15
We have dedicated servers for development and staging environments.
So we just setting ASPNETCORE_ENVIRONMENT at system level to "Development" or "Staging".
That protect us from developers forgetting to set this value in configs.

But with this configuration Microsoft.IIS.Administration can't start when registered as service.

@drago-draganov
Copy link
Contributor

@kae
This is a bug in IIS Administration API. It will be addressed with the next release later this week.

Saying that, I would avoid using system wide environment variables, unless absolutely necessary. I suppose your goal is to setup particular environment for your applications/services, not the entire system? Globally set ASPNETCORE_ENVIRONMENT could likely effect (unexpectedly) any app/service that uses ASP.NET Core on that machine.

A recommended approach is to add ASPNETCORE_ENVIRONMENT before starting your app/service. For services it's handy to configure using the service regkey:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\YourServiceName

Add value
Name: Environment, Type: REG_MULTI_SZ

Add any environment variables as follows:
ASPNETCORE_ENVIRONMENT=Development
Name1=Value1

Hope it can help unblock you for now.

@kae
Copy link

kae commented Aug 9, 2017

@drago-draganov
Thanks for reply.
But as I note in my comment "That protect us from developers forgetting to set this value in configs"

Missing ASPNETCORE_ENVIRONMENT lead to using production settings from configs in dev environment, which is really inconvinient and considered dangerous by us.

Thats why our choice was global system settings.

@drago-draganov
Copy link
Contributor

Thanks for reporting it, @kae !

Do you configure and run all of your ASP.NET Core apps as IIS web applications, or they are standalone windows services?

@kae
Copy link

kae commented Aug 9, 2017

@drago-draganov
Mostly it's IIS based
And one app, that is service based (it was started before asp.net core, and was owin/katana based)

@drago-draganov
Copy link
Contributor

Then you may be able to use HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC to configure ASPNETCORE_ENVIRONMENT for all ASP.NET Core applications that are hosted in IIS.

The problem with global ASPNETCORE_ENVIRONMENT is well outlined by your scenario. Consider 3rd party or system services that can suddenly start behaving unexpectedly, because they will see Development config/settings. For them it's production environment.

We eliminated the dependency of ASPNETCORE_ENVIRONMENT in IIS Administration API. An official build will follow shortly. Thanks for pointing out the issue. Appreciate it!

@kae
Copy link

kae commented Aug 9, 2017

Thanks, will try your solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants