Use Windows azure web sites to build hosted web applications

Source: Internet
Author: User

Windows azure web sites (waws) is a service built on the Windows azure platform as a service (PAAs) framework, which simplifies and hosts cloud applications.ProgramRelated deployment, management, and scalability tasks.

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
CreateASP. net mvc 4 WebApplications

 

InVisual StudioIn Solution ExplorerModelsAdd a data module under the folder, as shown in figureFigure. The attributes defined in the class module becomeSQL databaseTable structure. In this example, the Entity Framework simplifies the object.-Link ing. Entity Framework executableCrudOperations without the need to write ComplexSQLStatement.

Graph: Add a class to the models folder

 

In Solution Explorer, selectModelsFolder, from"Project"Select"Add Class...". Name this classPerson.PersonClass will becomeSQL ServerMediumPersonThe column of the table.

Public class person

{

Public int personid {Get; set ;}

Public String firstname {Get; set ;}

Public String lastname {Get; set ;}

}

 

ASP. net mvc 4Applications require the Controller class to serve as a bridge between views and models.

Compile the project before adding the Controller class. Slave"Build"Menu selection"Build Solution". In Solution Explorer, right-clickControllersFolder, and then select "add | controller ". As shown in"Add Controller"In the dialog box, follow these steps:

  1. In"Template"In the drop-down list, select"MVC controller with read/write actions and views, using Entity Framework".
  2. In"Model class"In the drop-down list, select"Person"Class.
  3. In"Data context class"In the list, select <new data context...>. In the displayed dialog box, set the namePersoncontextAnd then click"OK".
  4. In"Views"Select"Razor".
  5. Click"Add"To complete this 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.

FigureWindows azureQuick configuration of website deployment

 

The key step for deploying an application is to obtain the release configuration file, which containsVisual StudioWill be used to execute deployment settings. Depending on your browser, you may be able to download and publish the configuration file. You should save a local copy for futureVisual Studio.

 

Configure Data Service

InASP. net mvc 4You must configure the database before running the application.

FigureSQL database

 

Click"Add"The system requires you to set the login name and password, andWindows azure SQL databaseThe region where the deployment is located. We strongly recommend that you choose to runWawsTo minimize the latency and avoid bandwidth costs.

In our example, the login name isDbadministrator. 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 only allow specificIPAddress to establish an inbound connection. Click"Configuration". You will see the currentIPAddress, you can use it to create a rule and directlyIPAddress to connect to the server.

 

By Visual Studio Run Web Deployment

Now we want to create a database on the server We Just configured. ReturnVisual StudioSelect View | Solution Explorer ". Right-clickMvcazure. WebsiteAnd select"Publish", Will display the releaseWebDialog box.

This process is completed through the Wizard. The first step is to load the release configuration fileVisual StudioIn this way, you can greatly simplify the deployment process. You will perform several stepsASP. net mvc 4The application specifies the detailed information about how to publish the configuration file.MicrosoftInformation about the application deployed in the data center, includingWindows azure SQL databaseServer goalsURLAnd location.

SpecifyASP. net mvc 4TheWindows azure SQL databaseServer: ClickSettingAnd then clickPersoncontextThe ellipsis next to it ,.

Figure
Configure database connection

 

Now you need to enter the information when creating the database server. Please note that we have appended the server nameTCP. You also need to enter the Administrator name (Dbadministrator) And password.

Figure connecting to the server and creating a database

 

Click"OK"Then, it will be created on the server you enteredSQL database. The system will ask you to confirm this step. After creating a database, you canWebSelect "publish" in the application dialog box ". You canVisual StudioSelect"View | output"Window to view the steps during deployment.

After the application is deployed, you can easily monitor, expand, or upgrade the website. Of course, the first choice is to useWindows azureThe portal manages these tasks and provides dashboards that are easy to use.

 

Summary

ByWindows azure PAAsFunctions provided by components and preset frameworks (suchWordPress,Drupal,DotnetnukeAndUmbraco) In combination, developers can focus on building a wide rangeWebThe infrastructure tasks are delegated to applications and data repositories.Windows azurePlatform to execute.

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.