问题
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");
}
root web.config file:
<configuration>
<appSettings>
<add key="StorageConnectionString" value="UseDevelopmentStorage=true;" />
</appSettings>
</configuration>
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"
}
回答1:
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/en/latest/fundamentals/configuration.html
Also, have a look at this previous answer to a similar question:
https://stackoverflow.com/a/30580006/2823539
来源:https://stackoverflow.com/questions/38551528/asp-net-core-cloudconfigurationmanager-getsetting-is-null