Book Image

ASP.NET Core MVC 2.0 Cookbook

By : Jason De Oliveira, Engin Polat, Stephane Belkheraz
Book Image

ASP.NET Core MVC 2.0 Cookbook

By: Jason De Oliveira, Engin Polat, Stephane Belkheraz

Overview of this book

The ASP.NET Core 2.0 Framework has been designed to meet all the needs of today’s web developers. It provides better control, support for test-driven development, and cleaner code. Moreover, it’s lightweight and allows you to run apps on Windows, OSX and Linux, making it the most popular web framework with modern day developers. This book takes a unique approach to web development, using real-world examples to guide you through problems with ASP.NET Core 2.0 web applications. It covers Visual Studio 2017- and ASP.NET Core 2.0-specifc changes and provides general MVC development recipes. It explores setting up .NET Core, Visual Studio 2017, Node.js modules, and NuGet. Next, it shows you how to work with Inversion of Control data pattern and caching. We explore everyday ASP.NET Core MVC 2.0 patterns and go beyond it into troubleshooting. Finally, we lead you through migrating, hosting, and deploying your code. By the end of the book, you’ll not only have explored every aspect of ASP.NET Core MVC 2.0, you’ll also have a reference you can keep coming back to whenever you need to get the job done.
Table of Contents (26 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Creating and running an ASP.NET Core MVC application on Azure


In this recipe, we will create a web application and deploy it to Azure.

Getting started

We will use Visual Studio 2017 Community Edition, and create a web application using the ASP.NET Core templates in Visual Studio.

How to do it...

  1. First, let's create a new project by clicking New | Project | ASP.NET Core Web Application | Web application to create a web application running with ASP.NET Core:

Note

When you run a web application in Visual Studio 2017, you have the choice to develop, debug, and deploy a web application in two different runtime versions, which have themselves two versions for the processor architecture as follows:

  • CLR x86 (.NET 4.6 in 32 bits, only for Windows)
  • CLR x64 (.NET 4.6 in 64 bits, only for Windows)
  • CoreCLR x86 (.NET Core in 32 bits, cross-platform)
  • CoreCLR x64 (.NET Core in 64 bits, cross-platform)
  1. Let's do our first deployment by creating a website on Azure. To do that, right-click on the root of the project and select Publish....
  2. The Publish Web dialog box will open:
  1. Click Microsoft Azure App Service. The Create App Service dialog box will open:
  1. We have to give an App Name.
  2. Select the Subscription.
  3. Select an App Service Plan, or create one.
  4. Select a Resource Group (optional).
  5. Select a Region (optional).
  6. Select or create a Database Server (optional).
  1. Now the Create button is enabled, we click on it:

In the preceding screenshot, we can see a preview of the deployed files.

  1. Click Publish:

In the preceding screenshot, we can see the result of the build and the publishing in the output window.

In the following screenshot, we can see how our web application deployed on Azure:

Take a look at the screenshot below. We can see the publish settings for the web application in the PublishProfiles folder as one .pubxml file.

How it works...

We can publish the following applications to the Azure platform:

  • .NET web application
  • .NET Core web application
  • Java web application
  • Node.js web application
  • PHP web application
  • Python web application
  • Ruby web application

Azure makes it very easy to deploy and run web-based applications.