ASP.NET MVC的Windows Azure存储模拟器连接字符串?

时间:2021-11-08 17:20:03

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

我正在搜索需要定义为使用windows azure存储模拟器的连接字符串。

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.

到目前为止,我发现的所有资源都说这些连接字符串应该转到位于Windows Azure项目中的ServiceDefinition和ServiceConfiguration文件。但是,我没有使用Azure项目,而是使用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 ?

对于ASP.NET MVC项目,它应该可以转到web.config文件。但是,我不知道它应该是什么样的?

I have Azure account if that is needed for emulator.

如果模拟器需要,我有Azure帐户。

Thanks.

1 个解决方案

#1


12  

As this article says connectionstring is DevelopmentStorage=true

正如本文所说,connectionstring是DevelopmentStorage = true

So in Web.config you can use:

所以在Web.config中你可以使用:

  <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:

您可以使用CloudConfigurationManager,它将从Service Configratuon设置中获取配置(如果存在)。使用它喜欢这个:

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.

如果它在ServiceConfiguration中不存在,它将回退到web.config的应用程序设置。这样,如果您希望将应用程序移动到Azure,而不必更改检索连接字符串的方式。我倾向于将它全部隐藏在ISettingsProvider界面中(所以我不依赖于任何东西)但这可能是过度的。

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

将连接放入ServiceConfiguration的主要好处是您可以更改设置而无需重新部署应用程序。

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.

如果选择使用web.config,则可以使用transform将developmentstorage帐户换出为发布时的真实帐户。如果您使用Azure,则在云服务配置中只有一个不同的连接字符串。

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

不需要实际的Azure帐户来运行模拟器。

#1


12  

As this article says connectionstring is DevelopmentStorage=true

正如本文所说,connectionstring是DevelopmentStorage = true

So in Web.config you can use:

所以在Web.config中你可以使用:

  <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:

您可以使用CloudConfigurationManager,它将从Service Configratuon设置中获取配置(如果存在)。使用它喜欢这个:

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.

如果它在ServiceConfiguration中不存在,它将回退到web.config的应用程序设置。这样,如果您希望将应用程序移动到Azure,而不必更改检索连接字符串的方式。我倾向于将它全部隐藏在ISettingsProvider界面中(所以我不依赖于任何东西)但这可能是过度的。

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

将连接放入ServiceConfiguration的主要好处是您可以更改设置而无需重新部署应用程序。

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.

如果选择使用web.config,则可以使用transform将developmentstorage帐户换出为发布时的真实帐户。如果您使用Azure,则在云服务配置中只有一个不同的连接字符串。

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

不需要实际的Azure帐户来运行模拟器。