简体   繁体   English

asp.net core 1 appsettings.production.json没有更新连接字符串

[英]asp.net core 1 appsettings.production.json not updating connection strings

I had an application in production using .net core RC1 running on IIS. 我使用在IIS上运行的.net核心RC1生产了一个应用程序。 I re-wrote the application because the company wanted it on .net core1 since that is the official release. 我重新编写了应用程序,因为公司希望它在.net core1上,因为那是正式版本。

In my .net core RC1 application I had config.json and config.production.json and in the production version I simply included the settings I wanted overridden like the connection string. 在我的.net核心RC1应用程序中,我有config.json和config.production.json,在生产版本中,我只是包含了我想要覆盖的设置,如连接字符串。 That worked fine. 这工作得很好。

In .net core1 I have appsettings.json and appsettings.production.json. 在.net core1中我有appsettings.json和appsettings.production.json。 However, the connection string doesn't seem to be getting updated. 但是,连接字符串似乎没有更新。 It seems to use the localdb from the original appsettings.json. 它似乎使用原始appsettings.json中的localdb。

appsettings.json: appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-DecisionEff-b32ae861-2422-4f88-839c-2a6d599fee45;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

appsettings.production.json: appsettings.production.json:

{
    "ConnectionStrings": {
      "DefaultConnection": "Server=mydb.server;Database=DbName;User ID=User;Password=password;Trusted_Connection=False; Connection Timeout= 30;"
    }
}

In my startup file I do have it set to look for production: 在我的启动文件中,我确实将其设置为查找生产:

var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

The above was modeled after what I was doing in RC1 that worked. 以上是模仿我在RC1中所做的工作。 Was there something else that changed so connections strings are not udpated? 有没有其他的东西改变,所以连接字符串不是udpated? If I put the production db connection string in the appsettings.json file then the application works fine on our production server. 如果我将生产数据库连接字符串放在appsettings.json文件中,那么应用程序在我们的生产服务器上运行正常。 So it is not pulling the setting from the appsettings.production.json file. 所以它不是从appsettings.production.json文件中提取设置。 I know it is reading the environment properly because I am printing it out and it is as expected. 我知道它正在正确地阅读环境,因为我正在打印它并且它是预期的。

How do you provide different development and production db settings in .net core 1 web app? 您如何在.net core 1 Web应用程序中提供不同的开发和生产数据库设置?

Any help would be appreciated. 任何帮助,将不胜感激。 I am obviously overlooking something. 我显然忽略了一些东西。

UPDATE: When I run this on my local machine setting ASPNETCORE_ENVIRONMENT to Production it uses the proper connection string. 更新:当我在我的本地机器上运行它时,将ASPNETCORE_ENVIRONMENT设置为Production,它使用正确的连接字符串。 So the web app is seeing the proper environment on production and can use the connection string. 因此,Web应用程序在生产中看到了正确的环境,并且可以使用连接字符串。 Is there something that has to be configured during build to send the different environment settings? 在构建期间是否需要配置某些内容以发送不同的环境设置? Or is there a way it can print the different settings from the .json files for the environments? 或者有没有办法可以打印环境的.json文件中的不同设置?

UPDATE 2: I noticed that when I publish the application the there is only appsettings.json which has the localdb connection only. 更新2:我注意到,当我发布应用程序时,只有appsettings.json只有localdb连接。 There doesn't seem to be any appsettings.production.json file generated. 似乎没有生成任何appsettings.production.json文件。 Is there somewhere you have to specify during the build now that these different settings should come across? 现在是否需要在构建期间指定这些不同的设置应该遇到的地方?

You probably forgot to set the environment variable that sets the environment. 您可能忘记设置环境变量来设置环境。 You have to set ASPNETCORE_ENVIRONMENT to Production 您必须将ASPNETCORE_ENVIRONMENT设置为Production

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 核心 Web App appsettings.json 值替换为 Z05B6053C41A2130AFDZ6FC3B158B44B1 容器中的随机字符串 - ASP.NET Core Web App appsettings.json values replaced by random strings in docker container Appsettings.json 中的 Asp.Net Core & Sqlite 连接字符串 - 无法打开数据库 - Asp.Net Core & Sqlite connection string in appsettings.json - cannot open database ASP.NET核心EF代码首先appsettings.json - ASP.NET Core EF Code First appsettings.json ASP.NET Core appsettings.json 未加载正确的设置 - ASP.NET Core appsettings.json not loading the correct settings 用于 MSTest [ASP.NET Core 3.1] 的 appsettings.json - appsettings.json for MSTest [ASP.NET Core 3.1] AppSettings.json用于ASP.NET核心中的集成测试 - AppSettings.json for Integration Test in ASP.NET Core ASP.NET Core appsettings.json需要在磁盘上更新 - ASP.NET Core appsettings.json need to update on disk Serilog:RollingFile 在带有“appsettings.json”的 asp.net 核心中不起作用 - Serilog : RollingFile is not working in asp.net core with 'appsettings.json' 使用ASP.NET Core反序列化appsettings.json - Deserialize appsettings.json with ASP.NET Core ASP.NET Core appsettings.json 更新代码 - ASP.NET Core appsettings.json update in code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM