Hindi Video : Create Azure based ASP.NET MVC application in 30 minutes

 

Subscribe here to YouTube channel for all episodes

image

Cloud has been a buzz word for a while now. As a developer, we focus on converting the customer requirements to the code and sometimes find ourselves behind with the industry buzz words. The cloud is everywhere and perhaps the future. However as a developer, you won’t have to write very different code for cloud than codes you have been writing for the in-premise applications. In this post, I assume that you are already aware about MVC applications, hence I will focus on demonstrating how building for cloud is not very much different. I will follow step by step approach and create end to end MVC application completely hosted in the cloud (data and application both).

In this article, we will follow the following steps,

  • Setting up the database in the SQL Azure
  • Creating the MVC application
  • Building the application using MVC and the Entity framework
  • Publishing the application to Azure web site

Read full article on Infragistics blog

Subscribe here to YouTube channel for all episodes

 

 

 

 

 

Read article based on this video here

Subscribe here to YouTube channel for all episodes

I hope you like this video. Do not hesitate to leave comment or any feedback. Happy coding.

How to create a Container in Azure Storage from MVC application

I am working on a MVC application in which I need to work with Microsoft Azure storage .I had a requirement to create An Azure storage container from the MVC application. In this post I will share my learning that how I created a container programmatically.

I created the view as shown in below image. User has to enter the azure storage account name, azure storage key and the name of the container to be created.

image

Above View is MVC razor view, and it is created using the cshtml as shown below:

 


@{
    ViewBag.Title = "BLOB Manager";
}
<div class="jumbotron">
    <div class="row">
        <div class="col-md-8">
            <section id="loginForm">
                @using (Html.BeginForm("AzureInfo", "Manage", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
                {
                    @Html.AntiForgeryToken()
                    <h2> Manage BLOB Container</h2>
                    <hr />
                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                    <div class="form-group">
                        <div class="col-md-10 input-group input-group-lg">
                            @Html.TextBox("AccountName", "", new { @class = "form-control", @placeholder = "Account Name" })
                            @Html.ValidationMessage("AccountName", "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group">

                        <div class="col-md-10 input-group input-group-lg">
                            @Html.TextBox("AccountKey", "", new { @class = "form-control", @placeholder = "Account Key" })
                            @Html.ValidationMessage("AccountKey", "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group">

                        <div class="col-md-10 input-group input-group-lg">
                            @Html.TextBox("ContainerName", "", new { @class = "form-control", @placeholder = "Container Name" })
                            @Html.ValidationMessage("containername", "", new { @class = "text-danger" })
                        </div>
                    </div>
                    <div class="form-group input-group input-group-lg">
                        <div class="col-md-offset-2 col-md-10">
                            <input type="submit" value="Create Container" class="btn btn-lg btn-success" />
                        </div>
                    </div>

                }
            </section>
        </div>
    </div>
</div>

Above I am creating,

  • Three text boxes with the placeholder and the class set to bootstrap form-control
  • A submit button with the class set to bootstrap btn-lg and btn-success
  • All the controls are inside the form.
  • On form post operation, AzureInfo action of the Manage controller will be called.

Once the View is ready, let us go ahead and create an azure utility class. In this class we will put all the operations related to the azure storage. But before that you need to add Azure storage library to the project. Either you can use NuGet package manager or console to add the library. I am using console to install Azure storage library. I have taken the 4.3 version because at the time of writing this post, this was the latest stable version available.

image

Once package is successfully installed, add following namespaces.

 


using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure;

To create the container in the Azure storage, I have created a function CreateContainer. This function takes three input parameters, account name, account key and the container name.

 


public static class AzureUtility
    {
        public static string  CreateContainer(string AccountName, string AccountKey, string ContainerName)
        {

            string UserConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", AccountName, AccountKey);
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(UserConnectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(ContainerName.ToLower());
            if (container.CreateIfNotExists())
            {
                container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
                return container.Name;
            }
            else
            {
                return string.Empty;
            }
        }
    }

Now let us examine the above code line by line.

  • In first line I created the connection string for the azure storage. It takes two parameters, account name and the account key. These values are passed as input parameter to the function. I am using these two parameter to create connection string.
  • Using CloudStorageAccount to parse the connection string from the constructed string.
  • Creating the CloudBlobClient
  • Getting the container reference of the BLOB.
  • If container reference does not exist, creating new container.
  • On successful creation of the container function returns name of the container else empty string.

 


[HttpPost]
        public ActionResult AzureInfo(string AccountName, string AccountKey, string ContainerName)
        {

           var result= AzureUtility.CreateContainer(AccountName, AccountKey, ContainerName);

           if (result != string.Empty)
             {

                 return RedirectToAction("Index", "Home");
             }
             else
             {
                 return RedirectToAction("Index");
             }
        }

In the action we are using the utility class to create the container. In this way an azure container can be created from the MVC application.

I hope it is useful. Thanks for reading. Happy Coding.

What is Azure DocumentDB

Read full article on Falafel blog here

Recently I attended Cloud Camp by Microsoft India in Delhi. I had good time learning at the event. Besides other Microsoft Azure services like Azure Websites, Azure Mobile Services and Azure DocumentDB impressed me lot. In this post, I am sharing first level learning on Azure DocumentDB.

Azure DocumentDB is a NoSQL document database service offering on cloud from Microsoft. It allows us to work with schema free JSON documents using JavaScript and the HTTP protocol. It is a fully managed JSON document database service.

Some of the important points about the DocumentDB is as follows:

  • It is a schema free database
  • It has support of rich query and transaction processing
  • It uses JavaScript for the query
  • It works with JSON based data model
  • It works on HTTP protocol

Read full article on Falafel blog here

No Data tab in portal in Azure Mobile Services: Solved

Azure Mobile Service supports two platform for the backend. They are

  1. .NET backend
  2. JavaScript backend

I worked with JavaScript backend many times but with .NET backend it was my first attempt. So while creating Azure Mobile Service, I selected .NET platform as backend. To my surprise there is no Data tab available when you choose .NET backend.

clip_image002

Reason behind this is if you choose .NET backend data access becomes part of the .NET project and should be deployed from there. And in JavaScript backend Data tab would be visible in portal and scripts can run at the portal.

Steps to Enable Windows Azure Mobile Services

In this post we will take a step by step look on enabling Windows Azure Mobile Services in Windows Azure portal. To enable it login to Windows Azure Management Portal
After successful login to the portal in the bottom click on the New button.

 

image

On clicking of the NEW button under the COMPUTE tab, you need to select MOBILE SERVICES

image

You will get a screen with description of Mobile Services. Click on Try Now to enable Window Azure Mobile Services

image

In last step you will be prompted to select subscription and provide quick access token. However quick access token is optional.

image

In this way we can enable Windows Azure Mobile Services. I hope you find this post useful. Thanks for reading.

Error in installing Windows Azure Storage Client Library 2.0

To start working with Windows Azure Storage Client Library 2.0. I created a project and tried adding reference of Windows Azure Storage Client Library 2.0 using NuGet. When I tried installing, I got following error message.

“Microsoft.Data.OData could not be resolved”

image

This error message is clearly saying that you need to install Microsoft.Data.OData version greater than 5.0.2 to install Windows Azure Storage Client Library 2.0. To install this in NuGet Manager Package dialog search Microsoft.Data.OData and install it.

image

After installing this you should able to install Windows Azure Storage Client Library version 2.0 via NuGet. I hope you find this post useful. Thanks for reading.

Installing Windows Azure SDK on Visual Studio 2012

In this post we will do walkthrough of installing Windows Azure SDK on Visual Studio 2012. If Windows Azure SDK is not installed on your machine then on launching of Visual Studio 2012 and selecting Cloud project template, you will get option of Get Windows Azure SDK for .NET. Click on that.

You will get an option to Download Windows Azure SDK for .NET


Next you will be navigated to Windows Azure download page , Click on install the SDK


Choose Visual Studio 2012 to start installation


You will be prompted with confirmation box. Choose to run in the confirmation box 


You need to now click on Install button to start installing. 


Make sure all the prerequisite is installed and Accept Term and conditions. 


Windows Azure SDK will get start installing. After successful installation on launching of Visual Studio 2012 and selecting Cloud project tab, you will get Windows Azure Cloud Service project template to start working with Windows Azure projects. 


In this way you can install Windows Azure SDK on Visual Studio 2012. I hope you find this post useful. Thanks for reading it.