【发布时间】:2017-07-04 09:57:36
【问题描述】:
不,该指南似乎很清楚(至少对我而言)如何实施生产设置。他们只是谈论其中一些是如何工作的,但没有分步指南。我做了以下事情:
尝试使用 Guide 更改项目中的环境变量
尽管 Microsoft Doc 明确声明要重用 ASPNETCORE_ENVIRONMENT,但我仍然收到此错误。我无法保存这些设置
忽略此问题,您似乎可以在 launchSettings.json 中手动创建这些条目,所以我有:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:18549/",
"sslPort": 44319
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/v10Staff",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_ENVIRONMENT_T": "Test"
}
},
"IIS Express (Stage)": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/v10Staff",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Stage"
}
},
"ApplicationName": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:60000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_ENVIRONMENT_T": "Test"
}
}
}
向服务器添加环境变量
我已经根据我去Control Panel > System > Advanced system settings.的文档添加了环境变量并添加了`新用户变量。值为“阶段”的“ASPNETCORE_ENVIRONMENT”
使用这个Guide的配置片
我遇到的下一个问题是,没有人显示appsettings.Stage.json 的有效“转换”。它只是在 appsettings 文件上完全使用 Stage 文件吗?我需要明确说明有什么不同吗?这里说的是我的文件。
appsettings.Stage.json
{
"WebServiceAccount": {
"AccountName": "WebUser",
"AccountPass": "Wedontcarethatthisishere"
},
"ServerLocation": {
"ServerName": "http://appss.domain.com:8080",
"DBConnection": "server=svAppNameSTG;Max Pool Size=6000;database=ES;Integrated Security=SSPI;MultipleActiveResultSets=True"
}
}
appsettings.json
{
"WebServiceAccount": {
"AccountName": "WebUser",
"AccountPass": "testpass1"
},
"ServerLocation": {
"ServerName": "http://appst.domain.com:8080",
"DBConnection": "server=svAppNameTST;Max Pool Size=6000;database=ES;Integrated Security=SSPI;MultipleActiveResultSets=True"
}
}
我知道设置和配置块设置正确。因为我们的测试环境有效。当我将它部署到我们的 Stage 服务器时,我已经确认它仍然指向测试框。
如果有人有向导或能找出其中的问题,那就太好了。
为了后代
这里是启动构建器
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
【问题讨论】:
标签: asp.net json asp.net-core .net-core