.net core 中环境变量的配置

配置文件:

Properties目录下的launchSettings.json

IISExpress配置

"ASPNET_ENV": "EnvironmentOne"

Kestrel配置

"Hosting:Environment": "Development"

使用过程中发现个问题,估计是bug

修改launchSettings.json中的环境变量,IISExpress可以生效,但Kestrel的无论改成什么值,都是Development

解决办法:

通过图形界面修改就可以。

clipboard

推荐的几个配置

Development, Staging, Production

Development-开发环境

Staging-预生产环境(pre-production)或者说是模拟的生产环境,用来做最终测试

Production-生产环境

 

Startup类

默认都会走这个类,方法调用的顺序为

Startup --> ConfigureServices --> Configure

使用自定义的环境有两种方法(例如Development)

第一种通过方法名,第二种通过类

方法名需这样定义

ConfigureDevelopment

类则可以定义新的类

StartupDevelopment

类中的方法则和Startup中的一样即可

StartupDevelopment--> ConfigureServices --> Configure

两种都定义了,则使用类的方式

参考资料:

https://docs.asp.net/en/latest/fundamentals/environments.html

https://docs.asp.net/en/latest/fundamentals/startup.html

https://github.com/aspnet/Docs/tree/master/aspnet/fundamentals/environments/sample

posted @ 2016-03-30 10:16  draweye  阅读(1764)  评论(0编辑  收藏  举报