In the first part of this two part series I reviewed what table storage in Windows Azure is. In addition I began a how-to for setting up an ASP.NET MVC 2 Web Application for accessing the Windows Azure Table Storage (sounds like keyword soup all of a sudden!). This sample so far is enough to run against the Windows Azure Dev Fabric. However I still need to setup the creation, update, and deletion views for the site, so without further ado, let’s roll.
- In the Storage directory of the ASP.NET MVC Web Application right click and select Add and then View. In the Add View Dialog select the Create a strongly-typed view option. From the View data class drop down select the EmailMergeManagement.Models.EmailMergeModel, select Create form the View content drop down box, and uncheck the Select master page check box. When complete the dialog should look as shown below.
- Now right click and add another view using the same settings for Delete and name the view Delete.
- Right click and add another view using the same settings for Details and name the view Details.
- Right click and add another view for Edit and List, naming these views Edit and List respectively. When done the Storage directory should have the following views; Create.aspx, Delete.aspx, Details.aspx, Edit.aspx, Index.aspx, and List.aspx.
Now the next steps are to setup a RoleEntryPoint class for the web role to handle a number of configuration and initializations of the storage table. The first bit of this code will start the diagnostics connection string and wire up the event for the role environment changing. After this the cloud storage account will have the configuration for the publisher set so the configuration settings can be used. Finally the role environment setting will be setup so that it will recycle so that the latest settings and credentials will be used when executing.
- Create a new class in the root of the ASP.NET MVC Web Application and call it EmailMergeWebAppRole.
- Add the following code to the EmailMergeWebAppRole class.
[sourcecode language=”csharp”]
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
namespace EmailMergeManagement
{
public class EmailMergeWebAppRole
{
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
DiagnosticMonitor.Start("DiagnosticsConnectionString");
RoleEnvironment.Changing += RoleEnvironmentChanging;
CloudStorageAccount.
SetConfigurationSettingPublisher((configName, configSetter) =>
{
configSetter(RoleEnvironment.
GetConfigurationSettingValue(configName));
RoleEnvironment.Changed += (sender, arg) =>
{
if (arg
.Changes
.OfType()
.Any((change) =>
(change.ConfigurationSettingName == configName)))
{
if (!configSetter(RoleEnvironment.
GetConfigurationSettingValue(configName)))
{
RoleEnvironment.RequestRecycle();
}
}
};
});
return base.OnStart();
}
private static void RoleEnvironmentChanging(object sender,
RoleEnvironmentChangingEventArgs e)
{
if (e.Changes.Any(change =>
change is RoleEnvironmentConfigurationSettingChange))
{
e.Cancel = true;
}
}
}
}
}
[/sourcecode]
- Now open up the StorageController class in the Controllers directory.
- Add an action method for the List view with the following code.
[sourcecode language=”csharp”]
public ActionResult List()
{
var emailMergeListing = new EmailMergeRepository().Select();
return View(emailMergeListing);
}
[/sourcecode]
- Add the following two actions to the StorageController Class.
[sourcecode language=”csharp”]
public ActionResult Create()
{
return View();
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(EmailMergeModel emailMergeModel)
{
if (!ModelState.IsValid)
return View();
emailMergeModel.LastEditStamp = DateTime.Now;
emailMergeModel.RowKey = Guid.NewGuid().ToString();
var emailMergeRepository = new EmailMergeRepository();
emailMergeRepository.Insert(emailMergeModel);
return RedirectToAction("List");
}
[/sourcecode]
- On the Index.aspx view add some action links for the following commands.
[sourcecode language=”html”]
<ul>
<li>Email Merge Items
<%: Html.ActionLink("List", "List", "Storage") %>.</li>
<li>
<%: Html.ActionLink("Create", "Create", "Storage") %>
a new Email Merge Item.</li>
</ul>
[/sourcecode]
- Open up the Create.aspx view and remove the following HTML & other related markup from the page.
[sourcecode language=”html”]
<div class="editor-label">
<%: Html.LabelFor(model => model.LastEditStamp) %></div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.LastEditStamp) %>
<%: Html.ValidationMessageFor(model => model.LastEditStamp) %></div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Timestamp) %></div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Timestamp) %>
<%: Html.ValidationMessageFor(model => model.Timestamp) %></div>
<div class="editor-label">
<%: Html.LabelFor(model => model.PartitionKey) %></div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.PartitionKey) %>
<%: Html.ValidationMessageFor(model => model.PartitionKey) %></div>
<div class="editor-label">
<%: Html.LabelFor(model => model.RowKey) %></div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.RowKey) %>
<%: Html.ValidationMessageFor(model => model.RowKey) %></div>
[/sourcecode]
There is now enough collateral in the web application to run the application and create new EmailMergeModel items and view them with the list view. Click on F5 to run the application. The first page that should come up is show below.

Click on the Windows Azure Table Storage link to navigate to the main view of the storage path. Here there is now the Create and List link. Click on the Create link and add a record to the table storage. The Create view will look like below when you run it.

I’ve added a couple just for viewing purposes, with the List view now looking like this.

Well that’s a fully functional CRUD (CReate, Update, and Delete) Web Application running against Windows Azure. With a details screen to boot.
Truly amazing article…..Really thankful to you. It helped me lot. There are some other good articles too helped me in completing my task. You may check this links….
http://www.mindstick.com/Articles/106add7e-1856-4030-b101-718035954dbb/?Insert,%20Update,%20Delete%20in%20Windows%20Azure%20Application
http://blogs.msdn.com/b/windowsazure/archive/2012/02/09/windows-azure-isv-blog-series-sociobridge-by-reedrex-windows-azure-isv-blog-series-sociobridge-by-reedrex.aspx
Thanks Everyone for your precious post.