Windows Azure Storage Emulator Connection String for ASP.NET MVC?

狂风中的少年 提交于 2019-12-03 16:11:23

As this article says connectionstring is DevelopmentStorage=true

So in Web.config you can use:

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

In ServiceConfiguration.cscfg:

  <Setting name="StorageConnectionString" value="UseDevelopmentStorage=true" />

You can use CloudConfigurationManager it will get the configuration from the Service Configratuon settings if it exists. Use it likes this:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString"));

If it doesn't exist in ServiceConfiguration it will fall back to the application settings of your web.config. That way if you move application to Azure if you want and not have to change anything in how you retrieve your connection strings. I tend to hide it all in an ISettingsProvider interface (So I don't take a dependency on anything) but that is probably overkill.

The main benefit of putting connection in the ServiceConfiguration is that you can change the setting without having to re-deploy the application.

If you choose to use web.config then you can use transform to swap out the developmentstorage account to a real account on publish. If you use Azure just have a different connection string in the Cloud service configuration.

Don't need actual Azure account to run the emulator.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!