Welcome to Azure – Getting Started: Codename Aduze

I have not had an official chance to work deeply with Azure. Most of my knowledge come from reading here and there; from watching Pluralsight courses. I have knowledge about Azure but lacking skills. Besides Azure, ASP.NET Core has been there for a while; the latest is ASP.NET Core 2.0. I need to catch the train before it’s gone too far.

To learn technologies, you have to build something using them. I have to build a web application to get started. The focus is not about the business domain, it is about learning technologies. What should I call my project? Naming is always a problem 🙁

While thinking about Azure, when pronouncing in Vietnamese, there is a similar sound: A dua. It means “follow the trend, follow the crowd, …” Sounds like a good idea, I said. Because I am learning the newest technology stacks. Let’s call it: Aduze.

Aduze – Vietnamese Azure

I like it. Let’s start.

Starting with create a new project with ASP.NET MVC Razor (3) project template. Here what I got

ASP.NET Core 2 Project Template
ASP.NET Core 2 Project Template

Looks clean and simple. Press F5 and you have a website. Because I have been working with ASP.NET MVC, I understand most of the parts. The new stuff is the project file. Let’s take a quick tour Core Project File. One can click and view a detail explanation on MS Docs. To my learning, I just summary (repeat) them here

  1. Sdk: Specify the MSBuild tasks and target that will build the project. There are 2 valid IDs: Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web
  2. TargetFramework: the framework ID: netcoreapp2.0
  3. PackageReference: Define NuGet packages to restore while building.
  4. DotNetCliToolReference: CLI tool to restore. Not sure I understand what it is 😛

What is special about this project file? That is I could not find any file/folder reference. Remember the old days where a project file has all files/folders included in the project. We have not paid much attention to that until there is a conflict in a team. When 2 members add 2 different files, the end result is that, quite often, the other guy has to resolve the conflict.

wwwroot serves files from public access such as images, CSS files, or any file that allows public access. If I need to view the jquery license file, simply type http://localhost/lib/jquery/license.txt There is no wwwroot in the URL.

On Visual Studio, run the application with F5 and see the output

Core Web Server Console Output
Core Web Server Console Output

 

The ConfigureServices is called and then Configure. There are a whole bunch of other things we can learn such as which middleware invoked.

 

Step back and look at the default scaffold template. There are things I want fully understand first. When MVC first introduced, I jumped directly into the business code with the default scaffold template. And since then I have not had a chance to look back once. Mostly because there was no such a need for that. It was one of my learning mistake.

The Dependencies node tells us that there are 2 dependencies

  1. NuGet: Package manager
  2. SDK: Manage the build

Entry Point and Integration

The entry point is the Program class where it will start the application server Kestrel. Kestrel is responsible for running MVC application code. In the production environment, there will be 2 servers

  1. External Server: The old friend IIS (there are other in another OS but I just know IIS). IIS takes care of heavy tasks when dealing with outside world, things such as Security, DDoS, … before it sends the request to the internal server.
  2. Internal Server: Kestrel.

A developer can start a Kestrel server using dotnet command line (.NET Core CLI): dotnet run

The ASP.NET Core itself does not require or use web.config file. However, when hosting in IIS, there is a web.config file which is used by IIS; see the full explanation of AspnetCoreModule.

Startup

3 important things

  1. ConfigureServices: Where all dependencies are registered and setup
  2. Configure: Configure system components and pipeline (Middleware)
  3. Configuration (IConfiguration): Allow access to external configuration files. The obvious example is accessing values in appsettings.json file.

 

So far so good. I can understand the default project structure and how things work. Let’s deploy the application to Azure and explore more from there.

Deploying to Azure from VS2017 is super easy. Just right click on the web project and choose publish. What interesting is the files being deployed to Azure.

Publishing Azure
Publishing Azure

Those are files being deployed to Azure App Service. Notice that there is a web.config file. It does not exist in .NET Core 2.0 project

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\Aduze.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>
<!--ProjectGuid: 677f4bbf-84eb-44b7-a91e-b45ebfa48586-->

It registers AspNetCoreModule with App Service IIS so the communication between IIS and Kestrel work.

Wrap Up

I have not done anything special so far. Just look around the default template, try to understand pieces here and there.

  1. Understand the ASP.NET Core 2 Project template
  2. Understand IIS and Kestrel work together
  3. Understand the role of Program and Startup classes, as well as the Middleware pipeline. I wrote about it 1 year ago.
  4. It is easy to wire up a Kestrel web server (dotnet run CLI)

I will explore the Azure, Data Storage, and many other cool stuff using the project. More will come.

Have a nice weekend! (this post started days ago. I wrote along with my journey).

Write a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.