Windows Azure applications
ASP.NET, Windows Azure
Tutorial Tasks
Task 1 - Preparation
Task 2 - ASP.NET MVC3 application
Create new project (you can use a new empty solution) (Visual C# → Web → ASP.NET MVC3 Application).
Use project template - Internet application with an account controller that uses forms authentication.
Test application locally
Study application (role) structure. Identify parts of MVC.
Open Site.Master view, add item called “Submit message” into menu.
If you have time, rewrite the default content in order to represent a simple message board.
Extend corresponding controller (Home) and add a new view (Insertion).
Add new model MessageModel
Add action Insertion for storing message board messages.
Implement simple static class SimpleStorage to provide data container for messages.
Provide Index view with messages model (from corresponding controller).
Output content of MessagesModel in Index view.
Messages Model
public class MessageModel
{
[Required]
[DataType(DataType.Text)]
[Display(Name = "Your Message")]
public string Message { get; set; }
}
Insertion view
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.MessageModel>" %>
<asp:Content ID="aboutTitle" ContentPlaceHolderID="TitleContent" runat="server">
Message submission
</asp:Content>
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>Message submission</h2>
<% using (Html.BeginForm()) { %>
<div>
<fieldset>
<div class="editor-label">
<%: Html.LabelFor(m => m.Message) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(m => m.Message)%>
<%: Html.ValidationMessageFor(m => m.Message)%>
</div>
</fieldset>
<p>
<input type="submit" value="Uloz vzkaz" />
</p>
</div>
<% } %>
</asp:Content>
Insertion action
[HttpPost]
public ActionResult Insertion (MessageModel model, string returnUrl)
{
SimpleStorage.Messages.Add(model.Message);
return RedirectToAction("Index");
}
Messages model
public class MessagesModel
{
[DataType(DataType.Text)]
public List<string> Messages { get; set; }
}
Task 3 - Azure application deployment
There is currently problem to use visual studio tools for deploying azure applications. You can use direct upload of application package instead.
Add new project (Cloud → Windows Azure Project)
Don't add any roles (we will use the current one)
Add MVCApplication1 to Azure project roles (Roles→Add→Web Role Project in solution)
Configure the only web role (WindowsAzureProjectx → Roles → MvcApplicationx → right click).
Instance count = 2
VM size = extra small
Test application locally (if possible)
Cloud deployment
WindowsAzureProjectx → right click → publish
Choose your subscription → manage → new
Create new certificate, enter a friendly name
Copy full path of the certificate to clipboard
Go to windows azure portal → management certificate
Right click on your subscription → Add certificate → browse
Copy path to address bar → select certificate → click ok
Copy Subscription Id from Windows Azure Management Portal
Go back to Visual Studio and paste the Subscription Id
Choose your new subscription → Next
Leave settings as it is → Next → Publish
Wait until the role is published and the environment started. Test the deployment online. What is the problem?