Asp.net核心CloudConfigurationManager.GetSetting()为null

时间:2016-07-24 11:27:52

标签: azure asp.net-core azure-storage

我有一个asp.net 4应用程序,它工作正常,但我无法让它适用于asp.net核心。文档说明GetSettingweb.configapp.config文件中查找。 存储模拟器已打开。

public void ConfigureServices(IServiceCollection services)
{
    AzureConfig.Initialize();
}

public static void Initialize()
{
    //Always null
    var connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
}

root web.config文件:

<configuration>
    <appSettings>
        <add key="StorageConnectionString" value="UseDevelopmentStorage=true;" />
    </appSettings>
</configuration>

我在project.json中有这些依赖项:

"Microsoft.WindowsAzure.ConfigurationManager": "3.2.1",
"WindowsAzure.Storage": "7.1.2",
"AzureSDK2.2DLLs": "1.0.0"

编辑,这也不起作用:

  {
  "ConnectionStrings": {
    "DefaultConnection": "..."
    "StorageConnectionString": "UseDevelopmentStorage=true"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "StorageConnectionString": "UseDevelopmentStorage=true"
}

1 个答案:

答案 0 :(得分:3)

在ASP.NET核心中,设置已移出web.config并移至appsettings.json。看一下文档的变化:

https://docs.asp.net/en/latest/fundamentals/configuration.html

此外,请查看以前对类似问题的回答:

https://stackoverflow.com/a/30580006/2823539