I have a .net core web project which I'm publishing to IIS on Windows (10 or Server). I cannot seem to get IIS to provide the connection string through the Configuration Editor. I want the connection strings here so that it's not overwritten after every deploy.
I have tried using ASPNETCORE_ConnectionStrings__DefaultConnection and ConnectionStrings:DefaultConnection but neither do the job I always get a 500 error stating that the connection string cannot be null.
What am I missing here?
Here's part of my Startup.cs file: Note that this application was in a time before the default config did this for you.
public class Startup
{
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)
.AddUserSecrets<Startup>()
.AddEnvironmentVariables();
Configuration = builder.Build();
}
}
Edit:
I've setup a brand new .Net Core 2.2 app. Even with the newer program/startup. The connection string doesn't come through.
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args) //<-- adds config.AddEnvironmentVariables();
.UseStartup<Startup>();
}
