Table of Contents
- π― What Youβll Learn in This Blog
- π₯οΈ Hosting a Web App Inside a Virtual Machine
- π» Creating the Web App in Visual Studio
- π Hosting the App in IIS
- β Local Access vs Public Access
- π Securing the Web App in VM
- π‘οΈ The Right Solution β Application Gateway
- π§© 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)
- Go to
π Server Manager β Add Roles and Features - Select:
β Web Server (IIS) role
β Under features, enable IIS 6 Management Compatibility - 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
- Open Visual Studio
- Create a project:
π ASP.NET Core Web App (ModelβViewβController) - Make a small UI change to:
Home β Index.cshtml
(so you can recognize your app later)

π¦ Step 5 β Publish as Folder
- Right click project β Publish
- Choose β Publish to Folder
In settings select:
- β
Self-contained deployment
(so app runs without external dependencies)
- Copy the published folder into the VM.
π Hosting the App in IIS
π οΈ Step 6 β Configure IIS Website
- Open IIS Manager in the VM
- Remove the default website
- Click Add Website

Configure:
- π Physical path β your published folder
- π Port β 8080
π The publish folder must be the parent of the
wwwrootfolder.


π 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
- π¨ DDoS Attacks
Bots flood your app with requests so real users cannot access it. - 𧨠Cross-Site Scripting (XSS)
Malicious scripts injected into your pages. - π SQL Injection
Attackers manipulate database queries. - π 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!

Leave a Reply