Deploy .NET Core MVC Application on Azure Cloud

In this article I will be explaining about deploying .NET Core MVC Application on Azure Cloud step by step in detail. 

There are following deployment stages involved 

1) Signup in Azure 2) Creating a Resource Group 3) Creating a VM 4) Creating a Azure sql server Database 5) Publish your MVC Application 6) install IIS web server feature in VM 7) deploy your publish files in IIS


 

 

 

Lets discuss each steps in detail. 

1) Signup in Azure 

You can signup to azure using below link you will get 1 month free trial for using azure services.

https://azure.microsoft.com/en-us/free/ 

once you signup with azure, you are ready to do the next steps in the article.

2) Creating a Resource Group

login to azure portal where you can get links to use various services and home page look like below figure.

azure portal

 

In above portal you can type "resource group" in search bar you can create the Resource Group. type the resource group name and select the desired region and click on review +create button. Then you can verify the details entered in next screen and then click on Create button as shown in below figure. that's it your resource group has been created.

 
 

resource group 2
 

 

3) Creating a VM 

 Now our resource group is ready lets create vm for app server. Now go to azure portal home page and just hover your mouse to virtual machines icon and you will get create virtual machine button, click on that then you will be redirected to virtual machine creation wizard.

  1. Select the resource group from drop down
  2. Enter virtual machine name
  3. select the desired region
  4. select the Availability options, select no infrastructure redundancy required if you are just creating for knowledge. If you are planning to deploy for production then i recommend that select the multiple availability zone so that your application will be highly available.
  5. Select security type to standard
  6. select image => i have selected windows server 2022 data center 
  7. Select size(resource)=> select standard_B1s
  8.  enter User name and password fields (this credentials will be used to login to vm via rdp session please take a note of it.)
  9. in Public inbound port select allow selected ports
  10. in select inbound port drop down select RDP (3389) option
  11. now click on disks tab and select OS disk type to standard SSD option
  12. Then click on review + Create button you will get the all the information on the screen which you have entered in vm creation form.
  13. Click on create button and your VM will be created in few minutes.  

 

 

 

 

 

azure vm 5

 

4) Creating a Azure sql server Database

 Now go to azure portal home page and just hover your mouse to Sql Databases icon and you will get create button, click on that then you will be redirected to Sql Database creation wizard.

  1. Select the Resource Group from the drop-down
  2. Enter Database Name in Database name textbox
  3. Select the server from drop down, if you do not have server created then click on Create new link and enter the server details and save the details.
  4. Then click on Networking tab and select connectivity method to public endpoint
  5. in Firewall rule select yes to "Allow Azure services and resources to access to this server" option so that our application server can communicate with db server.
  6. Click on Review + create button and verify the details on next page
  7. Click on create button to create your sql database and server
  8. in Few minutes your Azure sql database will be ready for use. 

 

Azure Sql database

 

 

Azure Sql database 3


Azure Sql database 4

Azure Sql database 5



Azure Sql database 6


5) Publish your MVC Application

Now we have created azure vm and azure sql database now its time to publish our MVC application 

  1. Go to solution explorer in visual studio and right click on MVC project and ten click on publish option.
  2. Click on publish button in the publish wizard and your application will successfully gets published.
  3. Then go to publish directory and zip the publish file so that we can copy the same in our azure vm.

publish MVC app

 
publish MVC app 2


 

6) Install IIS web server feature in VM

Now we need to access our vm using RDP session for that we need to have the public IP address of vm. you can get it by following the below step.

  1. Go to azure portal home page and click on Virtual Machine icon, you will be redirected to virtual machine list page.
  2. Click on your virtual machine link to get the details of virtual machine 
  3. in your virtual machine page you will get the public IP address of your machine  
 
Azure vm public ip

Azure vm public ip 1

 

Now you know about your public IP address, you can get the RDP session using IP address and credentials which you have entered during the virtual machine setup. Once you get the RDP session follow the below steps to install IIS in the vm.

  1. Now go to System Properties >> Advanced .>> Go to virtual machine section and click on Change button. Click on custom size radio button and enter initial size 5000 MB and maximum size 6000 MB and click on set button and save the changes.(optional- since i have very low ram)
  2. Go to server manager and click on manage button on upper right corner then click on Add Roles and Features
  3.  Click on next button until you reach to Select Server Roles section and check Web Server (IIS) option and click on next button.
  4. Once you are in Role Service section check below additional Role Services with default selected role services
    1. Check all option of Management Tools
    2. Check .Net extensibility 3.5 and .Net extensibility 4.8 from application development section
  5. Click on Next button until you get install button and click on install button this will install the IIS web server on your vm

IIS install 1

 
IIS install 2

 

IIS install 3

IIS install 4

IIS install 5

We have installed the IIS web server now we need to install the .net core 3.1.28 hosting bundle in vm so that the .net core MVC app can be run using it. you just googled it you will end up as per following screen and download the bundle and install. It might happen that the bundle is already installed then you just click on repair button once install-shield screen appears.

.net core hosting bundle

.net core hosting bundle 2


Now we need to open port 80 for HTTP request in azure portal.

for that go to Virtual machines>>click on your VM>> then go to networking option from left pane of the portal. then click on Add Inbound port Rule button and add rule for port 80 as per below figure.

port open azure


7) deploy your publish files in IIS

 Just copy the published file zip file to vm for deploying application on IIS and extract to C:\inetpub

  • Open the Internet Information service manager and stop the default web site
  • Now right click on Sites and click on Add Website button 
  • Provide Site name and physical path and click on Ok button
  • Now we need to have connection string of azure db, for that follow the below steps
    • Go to azure portal home page.
    • Click on Sql databases.
    • Click on your created databases
    • Click on See connection string button
    • copy the connection string appears on the next page (Note: connection string does not contain the password, you need to update it manually) 
  •  now go to published application and update the connection string and then save the file. 
  • now browse the application by hitting localhost in browser, your application should load
  • you can try hitting application by public IP it should work as well. 

 

IIS Deployment

IIS Deployment 1

IIS Deployment  2

connection string Azure

connection string Azure 1

Final output

Final output 1

That's it , so these are the simple steps which can be helpful for deploying .net core MVC application on Azure Cloud.


Comments

Popular posts from this blog

Implement Logging in CSV file using Nlog in .net core MVC application- part 2

Implement Nlog in .Net core MVC application part 1

Angular User Session Timeout example step by step

Restore the lost focus of Auto post back controls in asp.net update Panel control

Disable backspace key using Jquery