最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net core - How can I set connection string settings in my reactjs Azure App service? - Stack Overflow

programmeradmin1浏览0评论

I have an Azure App service and I have deployed my react js app. In my local development environment, I have my appsettings.Development.json with the following setting:

  "ConnectionStrings": {
     "setting": "<connectionstring_details>",
  },

This setting needs to be set in my Azure app.

I have gone to the app under Environment variables --> ConnectionStrings and added a setting called "setting" and added the connectionstring_details value, but it did not work.

If I allow it to get the value from the appsettings.json file, not appsettings.Development.json because it is a release mode it works fine.

The way I retrieve the value in code is as follows:

public HomeController(IConfiguration configuration)
{
    MyValue = configuration.GetConnectionString("setting");
}

How can I set this value?

Do I need to just set it in the environment variables and not the connection strings ?

I have an Azure App service and I have deployed my react js app. In my local development environment, I have my appsettings.Development.json with the following setting:

  "ConnectionStrings": {
     "setting": "<connectionstring_details>",
  },

This setting needs to be set in my Azure app.

I have gone to the app under Environment variables --> ConnectionStrings and added a setting called "setting" and added the connectionstring_details value, but it did not work.

If I allow it to get the value from the appsettings.json file, not appsettings.Development.json because it is a release mode it works fine.

The way I retrieve the value in code is as follows:

public HomeController(IConfiguration configuration)
{
    MyValue = configuration.GetConnectionString("setting");
}

How can I set this value?

Do I need to just set it in the environment variables and not the connection strings ?

Share Improve this question edited Mar 6 at 6:14 Sirra Sneha 1,3482 gold badges3 silver badges10 bronze badges asked Mar 6 at 2:26 ClarisaClarisa 14 bronze badges 1
  • Set the connection string in Application Settings as ConnectionStrings_setting instead of using the Connection Strings section. – Sirra Sneha Commented Mar 6 at 6:39
Add a comment  | 

1 Answer 1

Reset to default 0

Actually, if you set the connections string inside the environment variable's connection string tab as below, you could directly get the connection string by using the configuration.GetConnectionString("setting")

My codes:

public HomeController(IConfiguration configuration)
{
    
    Myvalue = configuration.GetConnectionString("setting") != null ?  configuration.GetConnectionString("setting"): "test";
}

Result:

发布评论

评论列表(0)

  1. 暂无评论