asp.net-coreazure-web-app-service

How to set connection string settings for an ASP.NET Core app deployed to Azure?


I have a reactjs, ASP.NET Core app. In the appsettings.json file, I have the following connection string settings:

"ConnectionStrings": {
      "redis1": "<redis connectionstring>",
      "mssql1": "<mssql connection string>"
},

I have tried setting these in the Environment Variables -->Connection strings for the app, but it did not work. I also tried setting it in the environment variable, didn't work either.

Now the app gets these values the following way:

builder.Configuration.GetConnectionString("redis1"); 

and in other places as follows:

context.Configuration.GetConnectionString("redis1");

and

configuration.GetConnectionString("redis1") 

builder is of type FunctionApplicationBuilder, context is of type HostBuilderContext, and configuration is of type IConfiguration.

Where in the Azure app do I exactly set these values?


Solution

  • In the Environment variables tab. You'll need to name the setting correctly so it matches that appsettings.json.

    In this case: ConnectionStrings__redis1. Then set the value to the connection string you want to use.