2012-11-28 45 views
2

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

所有关于.NET的指南都讨论了如何在ServiceConfiguration中存储Azure存储连接信息(就像您在Cloud Service中那样),但是在Azure Web站点中我没有这个(只是一个Web.config)。如果我没有弄错,也无法使用RoleEnvironment(用于从ServiceConfiguration读取)而不在Azure模拟器中运行,并且我不在AzureWeb站点中执行此操作。

是否可以从Azure网站访问表存储,如果有,我该如何连接到它?我看过this question,看起来不像。

回答

5

你可以简单地得到从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> 
+0

谢谢,对我来说这并不明显看着指南。是否也可以使用本地开发存储(通过设置UseDevelopmentStorage = true并以某种方式启动Azure模拟器)? – Martin

+0

是的。您可以像这样启动存储模拟器:'C:\ Program Files \ Microsoft SDKs \ Windows Azure \ Emulator \ csrun.exe/devstore:start' –

1

简答:是的。 Table Service具有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/