I'm trying to define some environment variables in my web application. I host my site on Azure which has a staging deployment slot that the site goes to first, then, if the changes are signed off it's released to production.
The URLs for these two places are:
Production
"BaseUrl": "https://mycompany.azurewebsites.net"
Staging
"BaseUrl": "https://mycompany-staging2n1h.azurewebsites.net"
I want my appsettings.Staging.json file to be used when the site hits the staging area and then once it's released to production I want it to use appsettings.json.
It's my understanding that, if you don't define a production
appsettings.Production.jsonfile in your applicataion it defaults toappsettings.json.
So, I created a appsettings.Staging.json file within my application which contains a different connection string from the production environment.
appsettings.json
{
"AzureAd": {
"CallbackPath": "/signin-oidc",
"BaseUrl": "https://mycompany.azurewebsites.net"
},
"ConnectionStrings": {
"MyCompanyConnection": "production connection string"
},
"AllowedHosts": "*"
}
appsettings.Staging.json
{
"AzureAd": {
"CallbackPath": "/signin-oidc",
"BaseUrl": "https://mycompany-staging2n1h.azurewebsites.net"
},
"ConnectionStrings": {
"MyCompanyConnection": "staging connection string"
},
"AllowedHosts": "*"
}
I then went into the launchSettings.json file to set this up as follows:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:xxxx",
"sslPort": xxxx
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyCompany": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"MyCompany Staging": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
}
}
}
}
When I deploy my application to Azure and it hits the staging area, it's looking at the wrong connection string which means it's not using the correct appsettings file. Have I missed a step or set something up incorrectly?
