Reputation: 900
I would like to use the Azure Table Storage Service from an Azure Web Site (not a Cloud Service). There is guides on how to do this using Node.js but I like to use .NET MVC instead.
All the guides for .NET talks about storing the Azure Storage connection information in the ServiceConfiguration (as you do in a Cloud Service) but in an Azure Web site I do not have this (just a Web.config). If I am not mistaken it is also not possible to use the RoleEnvironment (used to read from the ServiceConfiguration) without running in the Azure emulator and I do not do this in an AzureWeb Site.
Is it possible to access the Table Storage from an Azure Web Site and if so how do I connect to it?
I have looked at this question and it does not look similar.
Upvotes: 2
Views: 996
Reputation: 24895
You can simply get the connection string from the web.config and parse it (note that you can also use the CloudConfigurationManager.GetSetting
method):
var connectionString = ConfigurationManager.AppSettings["myStorageAccountConnectionString"];
var storageAccount = CloudStorageAccount.Parse(connectionString);
var tableClient = storageAccount.CreateCloudTableClient();
And in your web.config you will need to add the connection string like this:
<appSettings>
<add key="myStorageAccountConnectionString" value="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=fazfazefazefzeefazeefazfazefazef"/>
</appSettings>
Upvotes: 5
Reputation: 11294
Short answer: yes. Table Service has a REST API, which means you can access it from any client platform that can communicate over http.
Googling then produces tons of examples:
http://azure.snagy.name/blog/?p=294
http://blogs.msdn.com/b/rickandy/archive/2012/09/20/azure-table-storage.aspx
You can use the CloudTableClient
from MVC: even if most examples are for Cloud Services, you can easily tweak them to get connection data from web.config, or from any other source. How-to docs are here: https://www.windowsazure.com/en-us/develop/net/how-to-guides/table-services/
Upvotes: 1