【问题标题】:Is it possible to acces a table storage in Azure from an Azure Web Site是否可以从 Azure 网站访问 Azure 中的表存储
【发布时间】:2012-11-28 18:18:29
【问题描述】:

我想使用 Azure 网站(不是云服务)中的 Azure 表存储服务。有关于如何使用 Node.js 执行此操作的指南,但我更喜欢使用 .NET MVC。

.NET 的所有指南都谈到在 ServiceConfiguration 中存储 Azure 存储连接信息(就像在云服务中所做的那样),但在 Azure 网站中我没有这个(只是一个 Web.config)。如果我没记错的话,如果不在 Azure 模拟器中运行,也无法使用 RoleEnvironment(用于从 ServiceConfiguration 中读取),而且我不在 Azure 网站中执行此操作。

是否可以从 Azure 网站访问表存储,如果可以,我该如何连接?

我查看了this question,它看起来并不相似。

【问题讨论】:

    标签: azure azure-table-storage


    【解决方案1】:

    您可以简单地从 web.config 中获取连接字符串并对其进行解析(注意您也可以使用CloudConfigurationManager.GetSetting 方法):

    var connectionString = ConfigurationManager.AppSettings["myStorageAccountConnectionString"];
    var storageAccount = CloudStorageAccount.Parse(connectionString);
    var tableClient = storageAccount.CreateCloudTableClient();
    

    在您的 web.config 中,您需要像这样添加连接字符串:

      <appSettings>
        <add key="myStorageAccountConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=fazfazefazefzeefazeefazfazefazef"/>
      </appSettings>
    

    【讨论】:

    • 谢谢,对我来说,看指南并不明显。是否也可以使用本地开发存储(通过设置 UseDevelopmentStorage=true 并以某种方式启动 Azure 模拟器)?
    • 是的。您可以像这样启动存储模拟器:C:\Program Files\Microsoft SDKs\Windows Azure\Emulator\csrun.exe /devstore:start
    【解决方案2】:

    简短的回答:是的。表服务有一个REST API,这意味着您可以从任何可以通过 http 进行通信的客户端平台访问它。

    然后谷歌搜索会产生大量示例:

    http://azure.snagy.name/blog/?p=294

    http://blogs.msdn.com/b/rickandy/archive/2012/09/20/azure-table-storage.aspx

    您可以使用 MVC 中的 CloudTableClient:即使大多数示例是针对云服务的,您也可以轻松地调整它们以从 web.config 或任何其他来源获取连接数据。操作文档在这里:https://www.windowsazure.com/en-us/develop/net/how-to-guides/table-services/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 2021-01-14
      • 1970-01-01
      • 2023-01-23
      • 2016-11-14
      • 1970-01-01
      相关资源
      最近更新 更多