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

落爺英雄遲暮 提交于 2019-12-05 00:22:49

问题


I am searching for the connection string that is need to be defined to use windows azure storage emulator.

So far, all the sources I have found says these connection strings should go to ServiceDefinition and ServiceConfiguration files located in Windows Azure project. However, I am not using Azure project but the ASP.NET MVC 3.

For, ASP.NET MVC project, it should probably go to web.config file. However, I have no idea what it should look like ?

I have Azure account if that is needed for emulator.

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/12436844/windows-azure-storage-emulator-connection-string-for-asp-net-mvc

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