Use Windows Azure Web Sites to build hosted Web applications
Windows Azure Web Sites (WAWS) is a service built on the Windows Azure platform as a service (PaaS) framework, this framework simplifies the deployment, management, and scalability tasks related to hosting cloud applications.
This article uses SQL Server as the data storage to create a simple and practical ASP. NET MVC 4 application, through examples to understand the basic elements of the WAWS service. This simple application supports creating, reading, updating, and deleting CRUD operations.
After you configure WAWS and generate an ASP. net mvc 4 application, we will deploy the application to the cloud using Visual Studio 2012.
Create an MVC Project
Open Visual Studio 2012 as an administrator and click "file" | "new" | "project ". Select "Web" from "installed template", and then select "ASP. net mvc 4 Web Application ". Name the project as MVCAzure. Website. Then you need to select the project template as "Internet application" and the view engine as Razor.
Figure 4 Create an ASP. net mvc 4 Web Application
In Visual Studio Solution Explorer, add the data class module under the Models folder ,. The attributes defined in the class module become the SQL Database table structure. In this example, Entity Framework simplifies object-link ing. Entity Framework can execute CRUD operations without writing complex SQL statements.
Graph: Add a class to the Models folder
In Solution Explorer, select the Models folder and select "Add Class…" from the "Project" menu... ". Name this class as Person. The Person class will be the column of the Person table in SQL Server.
Public class Person
{
Public int PersonID {get; set ;}
Public string FirstName {get; set ;}
Public string LastName {get; set ;}
}
ASP. net mvc 4 applications require the controller class to serve as a bridge between views and models.
Compile the Project before adding the Controller class. Select "Build Solution" from the "Build" menu ". In Solution Explorer, right-click the Controllers folder and select "Add | Controller ". In the "Add Controller" dialog box shown in, set the parameters as follows:
- In the "Template" drop-down list, select the "MVC controller with read/write actions and views, using Entity Framework" option.
- In the "Model class" drop-down list, select the "Person" class.
- In the "Data context class" list, select <New data context...>. In the displayed dialog box, set the name to PersonContext and click "OK ".
- In the "Views" drop-down list, select "Razor ".
- Click "Add" to complete the process.
Figure adding the MVC Controller class
Cloud deployment and creation of web sites services
You can use a continuous transfer framework (such as Git or TFS) or a simple tool (such as FTP) to deploy your website. In this article, we will use Web deployment in Visual Studio.
Log on to the Windows Azure Management Portal and log on to this URL: manage.windowsazure.com. Click "web sites" on the left of the browser window. Next, click "NEW | COMPUTE | web site | quick create" and enter the URL ,. Here we use mymsdnmagazine, which means our website is located in http://mymsdnmagazine.azurewebsites.net. Note that the URL name is unique.
Figure quick configuration of Windows Azure website deployment
The key step for deploying an application is to obtain the release configuration file, which contains the settings that Visual Studio will use to perform the deployment. Depending on your browser, you may be able to download and publish the configuration file. You should save a copy locally for later use in Visual Studio.
Configure Data Service
Before running ASP. net mvc 4 applications, you must configure the database.
Figure SQL Database
When you click "Add", the system requires you to set the logon name and password, and the region where you want your Windows Azure SQL Database to be deployed. We strongly recommend that you select the same data center where WAWS runs to minimize latency and avoid bandwidth costs.
In our example, the login name is DBAdministrator. This may be important if you want to perform remote operations or generate a connection string.
An important goal here is to protect your database server information and allow only specific IP addresses to establish inbound connections. Click "Configure" at the top of the screen ". You will see the current IP address. You can use it to create a rule and connect directly to the server from this IP address.
Web deployment by Visual Studio
Now we want to create a database on the server We Just configured. Return to Visual Studio and select "View | Solution Explorer ". Right-click MVCAzure. WebSite and select "Publish". The Publish Web dialog box is displayed.
This process is completed through the Wizard. The first step is to load the release configuration file to Visual Studio, which greatly simplifies the deployment process. You will perform several steps for ASP. net mvc 4 The application Specifies detailed information about the configuration file to be published and provides information about how to deploy the application in the Microsoft Data Center, this includes the target URL and location of the Windows Azure SQL Database server.
Specify the Windows Azure SQL Database server to be used by the ASP. NET MVC 4 Application by using the following method: Click Setting on the left side of the dialog box, and then click the ellipsis next to PersonContext ,.
Figure configuring database connection
Now you need to enter the information when creating the database server. Note that tcp is added before the server name. You also need to enter the Administrator name (DBAdministrator we set in the previous step) and password.
Figure connecting to the server and creating a database
After you click "OK", the SQL Database is actually created on the server you entered. The system will ask you to confirm this step. After creating a database, you can select "Publish" from the Publish Web application dialog box ". You can select "View | Output" in Visual Studio to View the steps during deployment.
After deploying an application, you can easily monitor, scale, or upgrade your website. Of course, the preferred method is to manage these tasks using the Windows Azure Portal, which provides easy-to-use dashboards.
Summary
Functions provided by the Windows Azure PaaS component are used in combination with preset frameworks (such as WordPress, Drupal, DotNetNuke, and Umbraco, developers can focus on building a wide range of Web applications and data repositories, and delegate infrastructure tasks to the Windows Azure platform for execution.
Include more technical documentation on Windows Azure development in the Windows Azure training package (http://www.windowsazure.com/en-us/develop/net/other-resources/training-kit.
References
Windows Azure Web Sites: Quick-and-Easy Hosting as a Service
Http://msdn.microsoft.com/en-us/magazine/jj883953.aspx
This article permanently updates the link address: