How to set up configuration parameters of .NET Core service deployed in Azure?

Connect to deployed service via FTP and open appsettings.json corresponding to release build. Add configuration object having the same structure as assumed by the application.

Example

 "AzureStorageConfig": {
    "ConnectionString": "...",
    "FileContainerName": "..."
 }

Corresponding .NET class has following structure.

 public class AzureStorageConfig
 {
     public string ConnectionString { get; set; }
     public string FileContainerName { get; set; }
 }

It is used as template of constructor parameter.

public class BlobStorage : IStorage
{
    private readonly AzureStorageConfig storageConfig;
    public BlobStorage(IOptions storageConfig)
    {
        this.storageConfig = storageConfig.Value;
    }
}

ASP.NET Core AppSettings for Azure App Service

Deploy ASP.NET Core apps to Azure App Service

Azure Tips and Tricks

Error “You do not have permission to view this directory or page” in Azure

There can be different reasons of that error. In my case this was lack of Global.asax file for ASP.NET application. To create this file on deploying application uncheck the flag “Precompile during publishing” in publish wizard.

Uncheck flag "Precompile during publishing" in publish wizard
Uncheck flag “Precompile during publishing” in publish wizard.

How to add custom configuration attributes to ASP.NET application

Configuring

Add configuration attributes to Web.config file.

Example

<configuration>
  <appSettings>
    <add key="UIVisible" value="false"/>
    <add key="MonitoringIntervalMs" value="1000"/>
    <add key="MonitoringDisabled" value="true"/>

Alternatively it’s possible to use Azure application attributes.

Reading from local Web.config

var appSettings = 
    (NameValueCollection) ConfigurationManager.GetSection("appSettings");
UiVisible = bool.Parse(appSettings["UIVisible"]);
MonitoringIntervalMs = int.Parse(appSettings["MonitoringIntervalMs"]);
MonitoringDisabled = bool.Parse(appSettings["MonitoringDisabled"]);

Reading from Azure

UiVisible = bool.Parse(CloudConfigurationManager.GetSetting("UIVisible"))