我有一个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");
}

根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"
}

最佳答案

在ASP.NET核心中,设置已从web.config中移出并移至appsettings.json中。请查看有关其更改方式的文档:

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

另外,请看一下先前对类似问题的回答:

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

关于azure - Asp.net核心CloudConfigurationManager.GetSetting()为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38551528/

10-10 21:00
查看更多