HOW TO write to and read from Windows Azure Tables via Azure Web Site

Windows Azure Web Site can be used not just for hosting a website but there are a host of other things you can do like hosting a WCF Service, leveraging the other services that Azure provides. Though most online samples show how to access Azure Tables from Windows Azure Cloud Service, Azure Table Storage can be accessed from an Azure Web Site too.

I found the article How to write to and read from Windows Azure tables within Web Applications by BrunoTerkaly, very well-written. It is short (unlike this one), provides adequate context, covers a practical scenario and has plenty of screenshots.

I adapted the steps in the article to access Windows Azure Tables from an Azure Web Site. If you want to try out the steps for an Azure Web Site, read that article & keep it open while you follow the steps below which are specific to Azure Web Site. You will need a Windows Azure account.

Bruno's article uses VS 2013 while I've got VS 2012. There are hardly any differences with respect to the steps. When I'm experimenting, I like starting out my ASP.NET web applications using the ASP.NET Empty Web Site template. So, here we go -

1. Omit steps 1-6 of that article and instead in VS 2012, from the menu choose File > New Web Site > ASP.NET Empty Web Site

2. Implement steps 7 to 9 of that article to install Windows Azure Storage libraries using the Package Manager Console
Click on images to enlarge

3. Add a Web Form & leave the name as Default.aspx

4. Copy the code within the div from step 11 of the article. As we are not using a Master page, we ignore the first 3 & last 2 lines of the sample code in that article.

5. Follow steps 12-14 to add the remaining code to make the sample work. Exclude this statement -
namespace WebAppWritesToAzureTables_WebRole

6. Steps 15-20 will help you create an Azure account & gain the credentials - "STORAGE ACCOUNT NAME","PRIMARY ACCESS KEY", to access an Azure Table.

7. In the file Default.aspx.cs, insert values for "STORAGE ACCOUNT NAME" and "PRIMARY ACCESS KEY" specific to your Azure account for the global variable account -
CloudStorageAccount account = new CloudStorageAccount(new StorageCredentials("STORAGE ACCOUNT NAME","PRIMARY ACCESS KEY"), true);

8. Hit F5 to run the application.

9. You can view the newly added records via View > Server Explorer, if you have Windows Azure Tools 

10. Specify the credentials for your Windows Azure Storage account

11. Once configured, you can view the data stored there

Also see:

Comments