Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure

When we start developing web applications in the cloud, there are several fundamental concepts or models that can be managed, among these, the concept of Infrastructure as a Service – IaaS. This model refers to an instant, resource-provisioned, and internet-managed computing infrastructure. This approach is one of four types of cloud services, along with models of Platform as a Service (PaaS), Software as a Service (SaaS), and Serverless Architecture. 
 
In Infrastructure as a Service, users of the IT team are the ones who handle all applications, data, operating systems, middleware, and runtimes, but let the provider, such as Azure, manage virtualization, storage, network, and servers. This way, your IT team doesn't need to have an organization-specific data center, and you don't have to worry about physically updating or maintaining these items, because that's what the vendor takes care of.
 
For the purposes of this article, we'll learn how to use this Infrastructure-as-a-service approach by creating a Virtual Machine with Windows Server 2019 and then deploying a web application developed in ASP.NET Core 2.2 using the Model, View, View-Model design pattern with DotVVM.
 
Required resources
  • An Azure account.
  • .NET Core SDK 2.2.
  • Visual Studio 2019.
  • The DotVVM extension for Visual Studio 2019. 
Activities to follow,
  • Create a Windows Server 2019 virtual machine in Azure.
  • Remotely configure the virtual machine so that you can work with ASP.NET Core and be able to deploy applications externally.
  • Additional configurations in the Azure resource for virtual machines.
  • Create the profile and deployment of ASP.NET Core web applications with DotVVM from Visual Studio 2019.
  • View the result of the published web page.

Create a VM in Azure

 
To get started, we need to have a subscription in Azure, if we don't have an account we can get a free one here.
 
As a first step, we need to go to the Azure portal and find the Virtual Machines resource and create a new one. In the creation process, we will have several important parts for the creation of the resource. Each of these parts is detailed below.
 
General aspects
 
You first need to specify the subscription and resource group, then the details of the instance to be created. This is where we'll define the operating system that the virtual machine will have and the size of it. For our goals, we will work with Windows Server 2019 Datacenter.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
As for the VM size, it will all depend on the number of Azure credits we can allocate for application deployment and the required amount of resources.
 
Then we need to define the virtual machine administrator account information through the user name and password. This data is very important as it will allow you to access the virtual machine later.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Finally, in the general section, we can define rules for virtual machine ports. In this case, we will enable port 80 for HTTP connections that will allow access to the website from the internet browser. The other port is RDP (3389), which will allow us to access the virtual machine remotely.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Specific aspects
 
Once the general aspects are specified, you can perform the general review and create the resource. In another scenario, we can also specify in detail the disk configuration for the virtual machine, either SSD or HDD type, network configuration and load balancing, management, and extension handling.
 
After these configurations are complete and after the creation process begins, this operation will take a few minutes to run.
 
With the resource ready, we can now head to the main section of the resource in Azure and download the access to allow us to remotely use the VM with Windows Server 2019. To do this we go to the Connect functionality and select the RDP option,
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 

Configuring the Windows Server 2019 Virtual Machine

 
Now that we have the Windows Server 2019 VM set up in Azure, we'll connect remotely from our computer. To do this, we run the file generated from Azure in the Connext – RDP (Remote Desktop Protocol) process to accomplish this goal.
 
In this case, the wizard will prompt us to enter the user authentication data (specified at the time of creating the resource in Azure) for access to the operating system. It will also be necessary to accept the certificate warning for the connection,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
With this process we will already have access to the virtual machine,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
When we start, the first thing to load is Server Manager: Dashboard where you can perform Windows Server configurations for later deployment. In this section of the article we will have three main activities: Install IIS (Web Server), Install Web Deploy, and Install .NET Core.
 
Installing IIS (Web Server)
 
Internet Information Services or IIS is a web server and set of services for the Microsoft Windows operating system. In this regard, IIS will act as the base server for working with .NET Core applications as ASP.NET Core with DotVVM.
 
However, for IIS installation we will go to the option: Add roles and features in the Server Manager Dashboard,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
When starting the setup wizard, we must accept the default settings in the Installation Type and Server Selection sections. In the Server Roles section, we will select Web Server (IIS) and accept the additional required installation of IIS Management Console.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
In the following sections, we will leave everything like this until we reach the Server Roles section. Here we will select the Management Service option under the Management Tools category. Additional installation of ASP.NET 4.7, in this case, is also required.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
With this done we have everything ready. Now we go to the Confirmation section to see the summary of the components to be installed and proceed with this operation.
 
Once the installation is complete there are two important considerations,
  • IIS is installed and runs with the internal firewall rule created for port 80.
  • Web Management Service is installed with the internal firewall rule created for port 8172.

Install Web Deploy

 
Web Deploy
 
Web deployment tool that simplifies the migration, management, and deployment of IIS web servers, web applications, and web sites.
 
In this case for the installation of Web Deploy, we must download the respective installer from Internet Explorer and perform the installation process like any other program. Since the default security rules in Azure prevent executables from being downloaded through Internet Explorer, we must first disable enhanced IE security.
 
To do this we go to the Local Server section of the Windows Server Dashboard and we are located in the property value IE Enhanced Security Configuration by clicking it.
 
Next, we change the value from On to Off,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
With this, we can already use Internet Explorer on Windows Server. Next, we go to the browser and download the Web Deploy 3.6 installer, which is available at the following address here.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Finally, we perform the installation process with the downloaded executable.
 
.NET Core in Windows Server 2019
 
With the configurations made so far, we can work with the deployment of applications with ASP.NET Framework 4.7. We intend to work with ASP.NET Core and DotVVM.
To do this, within Windows Server, in this case, we will proceed to install the SDK and the .NET Core Runtime & Hosting Bundle in version 2.2. The installers can be found at the following address here.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
When downloading the respective installers, we proceed with the execution of them. With this process, the Windows Server 2019 virtual machine hosted in Azure is ready with the required configurations.
 

Settings in Azure Virtual Machine from the portal

 
Up to this point, the Windows Server machine in Azure is ready. All we need is two important additional steps. It's about assigning the DNS (Domain Name System) of the virtual machine and enabling one of the ports to work with Web Deploy.
 
Configure DNS for the virtual machine
 
To perform this configuration, we need to go to the general section of the virtual machine in the DNS Name option and click Configure. Here we will define a unique DNS name (A green tick appears when the name is validated),
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Finally, we save the configuration.
 
Configure virtual machine inbound firewall rules
 
For the configuration in this section, we need to go to the Networking section within the VM resource in Azure and select the Add inbound port rule option to create a new firewall rule.
 
In this case, we'll add the WebDeploy rule - Port 8172 (Priority 1010),
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Finally, we added the new rule.
 
With all these configurations on Windows Server and on the VM resource in Azure, we're ready to deploy applications with ASP.NET Core and DotVVM.
 

Configuring the profile for deployment from Visual Studio 2019

 
With the entire procedure done so far, we now turn to the ASP.NET Core 2.2 web application solution with DotVVM that we are deploying to the VM in Visual Studio 2019. In this case, we will select the main solution project in Visual Studio 2019 and give you the right click on the Publish option,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
In this section, we'll create a new deployment profile through the option: Azure Virtual Machines. Here we will be asked to specify the Azure subscription and within it, select the VM resource,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Note
To successfully select the virtual machine, you need to verify that the virtual machine is powered on.
 
When you specify the virtual machine, the Visual Studio 2019 configuration wizard will verify that Windows Server has all the necessary settings for the deployment. If there are any errors these will appear in the profile, otherwise, no error will be displayed and the profile can be created,
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
For the final configuration we will go to the Edit option of the created profile,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
In this section, we will have the opportunity to save the access values (username and password) and test the connection to the server. Validating the connection requires accepting the certificate and saving the changes for later use. This part is very important for deployment.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
Finally, we will deploy the application on Windows Server located in Azure in the Publish option of the profile.
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
At this point, the process will begin and take a few minutes the first time.
 
The published website
 
As a result of all Windows Server VM configuration, azure settings, and deployment from Visual Studio 2019, the result is as follows for this case,
 
Deploying ASP.NET Core And DotVVM Web Applications To A Virtual Machine In Azure
 
What's next?
 
With this article, we've gone through step-by-step on how to deploy a web application with ASP.NET Core and DotVVM from Visual Studio 2019 to a Windows Server 2019 VM in Azure. 
 
Do you want to practice what you learned in this article? To do this you can see the following tutorial on CRUD Operations in DotVVM, access the source code, and implement this knowledge.
 
You can also review the following articles,
See you on Twitter!! :)