I cannot get my published ASP.net Core application to switch to using the connection string in my appsettings.production.json file.
I set startSettings to use the ASPNETCORE_ENVIRONMENT environment variable for my development and production profiles. When I switch profiles and run them in visual studio, my connection string changes correctly.
When I run the published application on my Ubuntu server, it does not switch. I set the ASPNETCORE_ENVIRONMENT variable to "Production" on my server. I also confirmed that both appSettings.json and appSettings.production.json exist in the root directory of the application.
My appsettings.json file:
{ "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } }, "ConnectionStrings": { "DefaultConnection": "server=localhost;user id=root;password=dev;database=testdb;sslmode=none", } }
my appsettings.production.json file is:
{ "ConnectionStrings": { "DefaultConnection": "server=localhost;user id=root;password=prod;database=testdb;sslmode=none" } }
My launchSettings.json file:
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:50824/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "home/index", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "IIS Express (Production)": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "home/index", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" } } } }
My Startup.cs:
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); if (env.IsEnvironment("Development")) {
I already mentioned these questions, but no luck:
asp.net core 1 appsettings.production.json does not update connection strings
dotnet publish does not publish the correct application settings. {env.EnvironmentName} .json