Deploy an ASP.NET application to Compute Engine

This tutorial describes how to a deploy a .NET Framework web application to Compute Engine.

This tutorial is intended for developers and DevOps engineers who have basic knowledge of Microsoft .NET and Compute Engine.


Deploy an ASP.NET Model-View-Controller (MVC) web-application that uses .NET Framework 4 and runs on Windows to a single Compute Engine instance.

This tutorial shows you how to complete the following tasks to reach your objective:

  • Deploy a Compute Engine VM
  • Set up load balancing
  • Deploy the ASP.NET application


In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator. New Google Cloud users might be eligible for a free trial.

When you finish the tasks that are described in this document, you can avoid continued billing by deleting the resources that you created. For more information, see Clean up.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Compute Engine API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Compute Engine API.

    Enable the API

Deploy a Compute Engine VM

This section shows you how to create a Linux VM, or a Windows Server VM that runs Microsoft Internet Information Services (IIS) web servers on Compute Engine.

  1. Set default values for your project ID and Compute Engine zone. This helps you save time.

    gcloud config set project PROJECT_ID
    gcloud config set compute/zone ZONE

    Replace the following:

    • PROJECT_ID with the ID of your Google Cloud project.
    • ZONE with the name of the zone that you're going to use for creating resources. If you are unsure about which zone to pick, use the zone geographically located closest to you.

    For example:

    gcloud config set project test-project-12345
    gcloud config set compute/zone us-central1-a
  2. Create a VM instance:

    To create a Windows Server VM that runs IIS, do the following:

    1. Create a startup script for the VM instance. This script will run during VM initialization and install IIS:

      "# Install IIS
      Enable-WindowsOptionalFeature -Online -FeatureName ``
          NetFx4Extended-ASPNET45, ``
          IIS-WebServerRole, ``
          IIS-WebServer, ``
          IIS-CommonHttpFeatures, ``
          IIS-HttpErrors, ``
          IIS-HttpRedirect, ``
          IIS-ApplicationDevelopment, ``
          IIS-HealthAndDiagnostics, ``
          IIS-HttpLogging, ``
          IIS-LoggingLibraries, ``
          IIS-RequestMonitor, ``
          IIS-HttpTracing, ``
          IIS-Security, ``
          IIS-RequestFiltering, ``
          IIS-Performance, ``
          IIS-WebServerManagementTools, ``
          IIS-IIS6ManagementCompatibility, ``
          IIS-Metabase, ``
          IIS-DefaultDocument, ``
          IIS-ApplicationInit, ``
          IIS-NetFxExtensibility45, ``
          IIS-ISAPIExtensions, ``
          IIS-ISAPIFilter, ``
          IIS-ASPNET45, ``
      Install-WindowsFeature Web-Mgmt-Service
      # Install WebDeploy
      [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType] 'Ssl3,Tls12'
      (New-Object Net.WebClient).DownloadFile(
      & msiexec /qb! /i $env:Temp\webdeploy.msi | Out-Default
      " | Out-File -Encoding ASCII startup.ps1
    2. Create the VM instance and run the startup script startup.ps1:

      gcloud compute instances create clouddemo-1 `
          --image-family windows-2019 `
          --image-project windows-cloud `
          --machine-type n1-standard-2 `
          --boot-disk-type pd-ssd `
          --tags loadbalancer-backend `
          --metadata-from-file sysprep-startup-script-ps1=startup.ps1
  3. Monitor the initialization process of the VM by viewing its serial port output:

    gcloud compute instances tail-serial-port-output clouddemo-1

    Wait about 5 minutes until you see the output Instance setup finished or Startup finished, and then press Ctrl+C. At this point, the installation of prerequisites is complete and the VM instance is ready to be used.

Set up load balancing

To make your ASP.NET app available over the internet, you have to use an HTTPS load balancer. To associate your VM instance with the load balancer, create an instance group and assign this instance group to the load balancer:

  1. Create an unmanaged instance group and add the VM instance:

    gcloud compute instance-groups unmanaged create clouddemo-1
    gcloud compute instance-groups unmanaged add-instances clouddemo-1 --instances clouddemo-1
  2. Create a health check that checks if the web server is running:

    gcloud compute http-health-checks create clouddemo-health `
        --check-interval 5s `
        --unhealthy-threshold 2 `
        --request-path /
    gcloud compute instance-groups set-named-ports clouddemo-1 --named-ports=http:80
  3. Create a load balancer backend service that uses the HTTP health check and the instance group that you created previously:

    gcloud compute backend-services create clouddemo-backend `
      --http-health-checks clouddemo-health `
      --port-name http `
      --protocol HTTP `
    gcloud compute backend-services add-backend clouddemo-backend `
      --instance-group clouddemo-1 `
      --global `
      --instance-group-zone $(gcloud config get-value compute/zone)
  4. Create a front-end for the load balancer:

    gcloud compute url-maps create clouddemo-map --default-service clouddemo-backend
    gcloud compute target-http-proxies create clouddemo-proxy --url-map clouddemo-map
    gcloud compute forwarding-rules create clouddemo-frontend --global --target-http-proxy clouddemo-proxy --ports 80
  5. Create a firewall rule that allows the load balancer to send HTTP requests to instances that have been annotated with the loadbalancer-backend tag.

    gcloud compute firewall-rules create loadbalancer-backend `
      --source-ranges "," `
      --target-tags loadbalancer-backend `
      --allow tcp:80,tcp:5000
  6. Lookup the IP address of the load balancer:

    gcloud compute forwarding-rules describe clouddemo-frontend --global --format "value(IPAddress)"

    Take note of the IP address. You will need it later.

Deploy the ASP.NET application

  1. Open a PowerShell console.

  2. Download and unzip or clone the sample repository from github:

    git clone
  3. Build the deployment package:

    1. Switch to the directory that contains the sample application:

      cd dotnet-docs-samples\applications\clouddemo\net4
    2. Restore NuGet dependencies:

      nuget restore
    3. Build the solution and use the PackageProfile publishing profile to create a WebDeploy deployment package:

      msbuild /t:clean,rebuild CloudDemo.Mvc.sln /p:DeployOnBuild=true /p:PublishProfile=PackageProfile

      The CloudDemo.Mvc\bin folder now contains a file

  4. Copy the deployment package to the VM:

    1. Create a username and password for the VM instance.
    2. Connect to the VM by using Remote Desktop and log in using the username and password created in the previous step.
    3. Copy the file from the CloudDemo.Mvc\bin folder to a temporary location on the VM instance.
    4. In the Remote Desktop session, right-click on the Start button (or press Win+X) and click Windows PowerShell (Admin).
    5. Confirm the elevation prompt by clicking Yes.
    6. Deploy the deployment package:

      &"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:package=PACKAGE -verb:sync -dest:auto

      Replace PACKAGE with the path to the deployment package.

  5. On your local computer, open a web browser and navigate to the following address:


    Replace LOADBALANCER_IP with the IP address that you obtained after deploying the load balancer.

    You now see the demo application and the title This app is running on Compute Engine.

Clean up

After you finish the tutorial, you can clean up the resources that you created so that they stop using quota and incurring charges. The following sections describe how to delete or turn off these resources.

Delete the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

    Delete a Google Cloud project:

    gcloud projects delete PROJECT_ID

Delete individual resources

You'll need to individually delete all the resources created for the project (for example: instance groups, health checks, backend services, http proxy, and forwarding rules). You can't delete the VM instances until delete all these resources.

What's next