Editor’s Note: The following is a guest post from Mustafa Mahmutović, a Microsoft Student Partner who attends the Faculty of Electrical Engineering at the University of Sarajevo where he is a Computer Science Major.

In this tutorial, you will learn how the built-in features of Visual Studio Community 2015 and the .NET framework do a lot of the work for you in when creating a web app. Using very little code, you’ll build a database of a movie collection. So, even if you are new to programming, you can use these tools and services to make something cool.

ASP.NET MVC is a web app framework that gives you a powerful way to build dynamic web apps. You’ll use ASP.NET MVC 5 and Entity Framework 6, which gets deployed on Azure App Service – Web App and Azure SQL Database.

You will need Microsoft AzureVisual Studio 2015 Community Edition and Microsoft Azure SDK for .NET (VS 2015) - 2.8.2. In addition, you will need to register and verify yourself as a student if you haven't already, which you can do here.

Let's get started!

Using your Microsoft Account, sign into Microsoft Azure. As you can see, there are many options on the Azure portal.

Leave Azure open in your browser, we'll use it later.

Step One: Develop an MVC Web App

Now it's time to develop our MVC Web App on Azure, using EntityFramework with CRUD (create, read, update and delete).

1. Open Visual Studio Community 2015 and log in to your Azure account.

2. Open cloud explorer to see all the projects or apps you have on your Azure account: View->Other windows->Cloud Explorer or View->Cloud Explorer (the second option in my version).

3. If you can’t find ‘Cloud Explorer’ in ‘Other Windows’, check ‘View’ in the list menu. When you have clicked ‘Cloud Explorer’, this is what you’ll see in Visual Studio.

Step Two: Create a New ASP.NET Web Application Project

Now let's create a new ASP.NET web application project.

1. To name a project, go to File->New Project->Web->ASP.NET Web Application. (For the purposes of this tutorial, I have kept the default option).

2. When you click ‘OK’, a new window will pop up. First, choose MVC, then make sure that you are using Azure and that ‘Host in the cloud’ is selected. Then click OK.

Step Three: Create an App Service

The next step will help you create a new app service on Azure. When the 'Configure Microsoft Azure Web App Settings' dialog appears, make sure that you are signed in to Azure.

1. First you will have to give a unique Web App Name (I named mine AppName WebApplicationOOAD). If you want to specify a name for your web app, change the value in the'Web App Name' The URL of the web app will be {name}.azurewebsites.net, so the name has to be unique in the azurewebsites.net domain. The configuration wizard suggests a unique name by adding a number to the project name "WebApplicationOOAD,“ which is fine for the purposes of this tutorial.

2. In the 'Subscription' box, you'll use your DreamSpark subscription.

3. For 'Resource Group', type the name of your new resource group. You can use one resource group for multiple projects or you can create a new resource group for each project that will be on Azure. I have named mine mvcAppGroup.

4. For 'App Service Plan', double-click on 'new', then choose the nearest region and click 'OK'.

5. When you are done, you should see something like this (except that you will have a DreamSpark subscription):

6. Click ‘create’.

Once your project is created, your first view will be the one shown below.

7. Now let’s test the default generated view on MVC Web App. Click on the start icon and select Microsoft Edge. Before that, you can see that ASP.NET already created Models, Views and Controllers for us. The browser will open your app and you will see this:

Step Four: Add a New Class

Now let’s go back to Visual Studio and add a new class to the project (this class represents a table and the properties represents the colums of that table).

1. Open the folder named ‘Models’, right-click and Add->New Item->Class.

2. Give a name to that class (I called it 'Movie').

3. On the class, create (or copy/paste) the following code:

4. You will get an error message on DbContext. Simply right-click on the error to resolve and add a library to the class: Entity or shortcut CTRL + . (dot) enter, enter. You will end up with something like this:

Step Five: Add a Controller using Scaffold

The next thing we’ll create is a Scaffold Item.

1. Right click on Controllers->Add->New Scaffolded Item

2. Now choose, ‘MVC 5 Controller with views, using Entity Framework’ and click ‘Add’.

3. Enter your model name in the empty fields.

4. If an error pops up like the screenshot below, just rebuild a solution and try to add a Scaffolded item again.

After the code generation process is complete, you will see a new controller and views in your project. The Controller was automatically created with CRUD operations. The Views were automatically created (open 'Views' and you will see a subfolder, 'Movies', and then 'Create,' 'Delete,' 'Details,' 'Edit.')

Step Six: Add Movies to Web App Display

Now we want to add a link to our main page to add or delete a movie.

1. Select Views->Shared->_Layout.cshtml

2. Find the code for the navgation bar under <div class = ''navbar-collapse collapse''>. After that line, simply add the following code:

@Html.ActionLink( displayed,view Name,folder name)

3. Now that you have displayed movies, you will be taken to the Movies index page.

Step Seven: Create a Server on Azure

Now we are ready to create a server on Azure.

1. Go to Azure. If you have closed that tab or browser, log in again. Important: Do not close Visual Studio!

2. Go to New->Data+Storage->SQL Database. Fill in the empty fields.

3. Name your database and click on Server->Create a new server. Add server name, admin, password and your location (just like for App Service location).

4. Click ‘OK’.

5. Remember your server name, admin login and password. In my example, it is ooadexample.database.windows.net. Select ‘Create’.

You will see that Azure is creating the database. Wait for it to finish.

Step Eight: Create Connection Strings

1. Select your database. Under the label ‘Connection Strings’, click on ‘Show database connection strings.’ Select the link in the ADO.NET box and copy it.

2. Go back to Visual Studio. Right click on ‘Project’ and click ‘Publish.’

3. This action launches the ‘Publish Web’ window. Paste the previously copied connection string into the ApplicationDbContext and MoviesDbContext fields. Then click on the three dots (…).]

4. The fields should automatically populate the correct information in the Destination Connection String window shown below. If not, enter your server name (in my example: ooadexample.database.windows.net) and password. Check ‘Save my password.’ Important: if password is not filled, enter your password and check “Save my password”.

5. Select ‘OK’.

Step Nine: Test the Published App

Your app will now open in your browser.

1. Click on ‘Movies.’

2. Test it by adding a title, release date, genre and price. Enter mm/dd/yyyy (American date time settings).

3. Creating a title here will also add it to your database on Azure. Close the tab and reopen it again to verify.

Step Ten: Verify Data in Azure

1. To verify that the movie data you entered in Step Nine appears in your Azure database, go to Visual Studio. Under ‘Cloud Explorer’, right-click on your database and click ‘Open in SQL Server Object Explorer’.

2. Now enter your server name, admin and password. Click ‘Connect’.

3. Once connected, you will see that the migration has indeed occurred.

Now you know how to upload an MVC web app to Azure using Entity framework and CRUD. I hope you've found it useful!

Microsoft Imagine, anywhere, anytime:

    • Follow us on TwitterFacebookInstagram and YouTube.
    • Subscribe to our blog to meet students just like you who are changing the world with their exciting new tech. Plus, stay on top of all the new products and offerings for students.
    • Get inspiration delivered to your inbox via our monthly Microsoft Imagine Newsletter, featuring the latest tech tips, competition news and all kinds of online tutorials.
    • Bookmark Microsoft Imagine for all the student developer news, downloads to free student products, online tutorials and contests you could want.

Microsoft Azure Tutorial: Build your first movie inventory web app with just a few lines of code的更多相关文章

  1. Azure Web App (一)发布你的Net Core Web 项目

    一,引言 今天我们看一下Azure上的一个服务-----Web 应用,我们都知道云计算的三大模式:Iaas(基础设施即服务),Paas(平台即服务),Saas(软件即服务). Iass,其实就是虚拟主 ...

  2. Azure Web App (三)切换你的Net Core Web 项目的数据库连接字符串

    一,引言 上一篇文章讲到今天我们演示了一下,如何在Web App中创建 “Deployment Slot”进行快速无停机部署新功能代码,也使用VS进行发布到创建的Web App中创建的新的部署槽位中, ...

  3. Microsoft Azure Project Oxford 体验

    2015年4月29日,微软在Build 2015大会上发布了一个震撼人心的项目: Project Oxford, 可以帮助直接实现图像理解.人脸识别.语音识别.语音合成等功能.虽然说这是号称研究院的项 ...

  4. Microsoft Azure 01 (Summarize)

    What is Windows Azure? As a cloud platform from Microsoft that provides a wide range of different se ...

  5. Microsoft Azure IoTHub Serials 1 - 使用Android设备与Azure IoTHub进行交互

    Azure IoTHub的目标是为物联网的应用场景提供方便的设备接入,完成消息的发送和接收(C2D和D2C).经过持续不断的努力,目前Azure IoTHub已经支持多种操作系统设备的接入,包括And ...

  6. Microsoft Azure IoTHub Serials 2 - 如何为android应用添加IoTHub支持

    1. 在build.gradle(app)文件的dependencies中添加对以下项的依赖: 'com.microsoft.azure.sdk.iot:iot-device-client:1.5.3 ...

  7. 学习笔记之Microsoft Azure

    Microsoft Azure - Wikipedia https://en.wikipedia.org/wiki/Microsoft_Azure Microsoft Azure (formerly  ...

  8. Microsoft Azure Overview

    Day1 Overview 1. Cloud - Internet scaling / Internet connects / Resource pool 2. Why the cloud?  Rap ...

  9. Azure KeyVault(三)通过 Microsoft.Azure.KeyVault 类库在 .NET Core 上获取 Secrets

    一,引言 上一篇文章,我们介绍了 Azure Key Vault 在实际项目中的用途,Azure Key Vault 作为密钥管理的服务,我们可以很轻松的利用它创建和控制用于加密的密钥,和管理证书和机 ...

随机推荐

  1. NameValueCollection类读取配置信息

    C#中的NameValueCollection类读取配置信息,大家可以参考下.   我首先介绍配置文件中的写法: 1.在VS2015中的工程下建立一个控制台应用程序,其config文件默认名称为App ...

  2. redis学习(七)——五大数据类型总结:字符串、散列、列表、集合和有序集合

    目录 字符串类型(String) 散列类型(Hash) 列表类型(List) 集合类型(Set) 有序集合类型(SortedSet) 其它命令 一.字符串类型(String) 1.介绍: 字符串类型是 ...

  3. 调试器GDB的基本使用方法

    GDB调试的三种方式: 1. 目标板直接使用GDB进行调试. 2. 目标板使用gdbserver,主机使用xxx-linux-gdb作为客户端. 3. 目标板使用ulimit -c unlimited ...

  4. 【C#复习总结】dynamic

    介绍 C# 4 引入了一个新类型 dynamic. 该类型是一种静态类型,但类型为 dynamic 的对象会跳过静态类型检查. 大多数情况下,该对象就像具有类型 object 一样. 在编译时,将假定 ...

  5. Spring MVC+ Spring + Mybatis从零开始搭建一个精美且实用的管理后台

    点击进入<SSM搭建精美实用的管理系统>达人课页面 SSM 框架即 SpringMVC+Spring+Mybatis,相信各位朋友在投递简历时已直观感受到它的重要性,JavaWeb 相关工 ...

  6. SVM(支持向量机)之Hinge Loss解释

    Hinge Loss 解释 SVM 求解使通过建立二次规划原始问题,引入拉格朗日乘子法,然后转换成对偶的形式去求解,这是一种理论非常充实的解法.这里换一种角度来思考,在机器学习领域,一般的做法是经验风 ...

  7. 每秒高达1.6亿次操作的并发键值存储库 FASTER 诞生

    FASTER 在过去十年中,云中的数据密集型应用程序和服务有了巨大的增长.数据在各种边设施(例如,设备,浏览器和服务器)上创建,并由云应用程序处理用来获得数据价值或做出决策.应用程序和服务可以处理收集 ...

  8. VS2017开发的IDE扩展

    Tag Helpers 智能提示 Razor Language Services: https://marketplace.visualstudio.com/items?itemName=ms-mad ...

  9. JS 作用域及作用域链

    一.作用域 在 Javascript 中,作用域分为 全局作用域 和 函数作用域 全局作用域: 代码在程序的任何地方都能被访问,window 对象的内置属性都拥有全局作用域. 函数作用域: 在固定的代 ...

  10. 动态规划-LIS最长上升子序列

    优化链接 [https://blog.csdn.net/George__Yu/article/details/75896330] #include<stdio.h> #include< ...