How to configure the application in .NET Core, which translates into the settings of the Azure application?

I can’t remember where I saw this, but I followed the advice on the blog when setting up my application configuration for my .NET Core MVC application. I created such a model to save some settings that I need for the application:

public class BasePathSettings
{
    public string BaseImageFolder { get; set; }
    public string BaseApiUrl { get; set; }
}

My StartUp has this ...

    public void ConfigureServices(IServiceCollection services)
    {
        ... 
        // this adds the base paths to container
        services.Configure<BasePathSettings>(Configuration.GetSection("BasePathSettings"));

        ....
    }

And appsettings.json has this in it:

"BasePathSettings": {
  "BaseImageFolder": "D:\\Images\\",
  "BaseApiUrl": "http://localhost:50321/"
},

I insert controllers that need this information, for example ...

    private readonly BasePathSettings _settings;

    public ClientsController(IOptions<BasePathSettings> settings)
    {
        _settings = settings.Value;

        _client = new HttpClient();
        _client.BaseAddress = new Uri(_settings.BaseApiUrl);
    }

Running this on my localhost is fine.

However, when I deploy this application to Azure, I suggested that I need to create an application setting in the general application service settings. So I made an application setup called BasePathSettings and copied the json for the parameter to the value:

 { "BaseImageFolder": "imagePath", "BaseApiUrl": "apiUrl" } 

, Azure barfs, ConfigureServices, , web.config NTFS. , , json Azure.

json? , -?

+4
2

json? , -?

- Azure, . ,

use BasePathSettings:BaseImageFolder to set your folder
use BasePathSettings:BaseApiUrl to set your url
+4

BasePathSettings json

-

basepathsettings:baseimagefolder (just single slash)
basepathsettings:baseapiurl

enter image description here

+2

Source: https://habr.com/ru/post/1672424/


All Articles