Asp.net核心CloudConfigurationManager.GetSetting()为null [英] Asp.net core CloudConfigurationManager.GetSetting() is null

查看:50
本文介绍了Asp.net核心CloudConfigurationManager.GetSetting()为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很好的asp.net 4应用程序,但无法在asp.net核心上运行.该文档说, GetSetting web.config app.config 文件中查找.存储模拟器已打开.

I have an asp.net 4 application where it works fine, but I can't get it working for asp.net core. The documentation says that GetSetting looks in either web.config or app.config file. Storage emulator is turned on.

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

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

根web.config文件:

root web.config file:

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

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

I have these dependencies in my project.json:

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

修改,该方法也不起作用:

Edit, this doesn't work either:

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

推荐答案

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

In ASP.NET core, the settings have been moved out of the web.config and in to appsettings.json. Have a look at the documentation for how it has changed:

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

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

Also, have a look at this previous answer to a similar question:

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

这篇关于Asp.net核心CloudConfigurationManager.GetSetting()为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆