🌍 2 – Web App In Virtual Network

Table of Contents

  1. 🎯 What You’ll Learn in This Blog
  2. πŸ–₯️ Hosting a Web App Inside a Virtual Machine
  3. πŸ’» Creating the Web App in Visual Studio
  4. πŸš€ Hosting the App in IIS
  5. ❗ Local Access vs Public Access
  6. πŸ” Securing the Web App in VM
  7. πŸ›‘οΈ The Right Solution – Application Gateway
  8. 🧩 Final Thoughts

🎯 What You’ll Learn in This Blog

In this blog, we will:

  • Deploy a web application inside an Azure Virtual Machine
  • Install and configure IIS + .NET 8 Hosting Bundle
  • Create an ASP.NET Core MVC app using Visual Studio
  • Publish the app and host it on the VM using IIS on port 8080
  • Understand why the app is accessible only locally and not via public IP
  • Learn the security risks of exposing VMs directly to the internet
  • See how Azure Application Gateway protects the web app

By the end, you’ll know how to host a real web app in a VMβ€”and more importantly, how to secure it πŸ”.


πŸ–₯️ Hosting a Web App Inside a Virtual Machine

To run a web application inside a VM, we must first turn the VM into a web server.

🧰 Step 1 – Connect to the VM

  • Use Remote Desktop (RDP) to log in to your Azure VM
  • Open Server Manager

🌐 Step 2 – Install IIS (Web Server)

  1. Go to
    πŸ‘‰ Server Manager β†’ Add Roles and Features
  2. Select:
    βœ” Web Server (IIS) role
    βœ” Under features, enable IIS 6 Management Compatibility
  3. Wait for installation to finish ⏳

After installation you will see:

C:\inetpub\wwwroot

This folder contains the default IIS landing page.

βœ… You can test it inside the VM by opening:
http://localhost


βš™οΈ Step 3 – Install .NET 8 Hosting Bundle

Download and install the latest .NET 8 Hosting Bundle inside the VM so IIS can run ASP.NET Core apps.

πŸ’‘ Without this bundle, IIS cannot host .NET applications.


πŸ’» Creating the Web App in Visual Studio

πŸ§ͺ Step 4 – Build an ASP.NET Core App

  1. Open Visual Studio
  2. Create a project:
    πŸ‘‰ ASP.NET Core Web App (Model–View–Controller)
  3. Make a small UI change to:
    • Home β†’ Index.cshtml
      (so you can recognize your app later)

πŸ“¦ Step 5 – Publish as Folder

  1. Right click project β†’ Publish
  2. Choose β†’ Publish to Folder

In settings select:

  • βœ… Self-contained deployment
    (so app runs without external dependencies)
  1. Copy the published folder into the VM.

πŸš€ Hosting the App in IIS

πŸ› οΈ Step 6 – Configure IIS Website

  1. Open IIS Manager in the VM
  2. Remove the default website
  3. Click Add Website

Configure:

  • πŸ“ Physical path β†’ your published folder
  • 🌐 Port β†’ 8080

πŸ“Œ The publish folder must be the parent of the wwwroot folder.


πŸ‘€ Step 7 – Test Locally

Click Browse :8080

Your web app opens at:

πŸ‘‰ http://localhost:8080

πŸŽ‰ The app is now running inside the VM!


❗ Local Access vs Public Access

Right now:

  • βœ… App works inside the VM
  • ❌ App is NOT accessible using the VM’s public IP

You could open port 8080 to the internet…
πŸ‘‰ But this is a BAD idea.


πŸ” Securing the Web App in VM

Exposing a VM directly to the internet introduces serious risks.

⚠️ Common Security Threats

  1. 🚨 DDoS Attacks
    Bots flood your app with requests so real users cannot access it.
  2. 🧨 Cross-Site Scripting (XSS)
    Malicious scripts injected into your pages.
  3. πŸ’‰ SQL Injection
    Attackers manipulate database queries.
  4. πŸ“‰ HTTP Protocol Violations
    Malformed requests to crash or exploit the app.

❌ Opening inbound port 8080 is NOT recommended
Even RDP port should be closed in production.


πŸ›‘οΈ The Right Solution – Application Gateway

Instead of exposing the VM:

  • All traffic should enter through Azure Application Gateway
  • Gateway validates and filters requests
  • Only safe traffic reaches the web app

βœ… Benefits

  • Web Application Firewall (WAF)
  • DDoS protection
  • SSL termination
  • Central entry point
  • No direct VM exposure

🧠 Architecture Idea
Internet β†’ Application Gateway β†’ VM Web App
NOT β†’ Internet β†’ VM directly


🧩 Final Thoughts

You have now learned:

  • How to convert a VM into a web server
  • Host an ASP.NET Core app in IIS
  • Why local access β‰  public access
  • The dangers of exposing VMs
  • The importance of Application Gateway

πŸš€ Real-world rule:
Never expose VMs directlyβ€”always use a gateway!

Comments

Leave a Reply

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

TechMilestoneHub

Build Skills, Unlock Milestones

This is a test – edited from front page