<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


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:

Labels: ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

»

Post a Comment