ASP.NET is an open source web framework for building modern web apps and services with .NET. ASP.NET creates websites based on HTML5, CSS, and JavaScript that are simple, fast, and can scale to millions of users.

In this lab, you deploy a simple ASP.NET app to Windows Server running on Compute Engine. This codelab builds on the Deploy Windows Server with ASP.NET Framework to Compute Engine codelab. Make sure you have completed that lab and have Windows Server with ASP.NET Framework running on Compute Engine. Also, make sure you remember the Windows username and password you created, as you will need them in this lab.

Additionally, you will need Visual Studio 2013 or later to write your ASP.NET app and deploy it to Compute Engine.

What you'll learn

What you'll need

How will you use this tutorial?

Read it through only Read it and complete the exercises

How would rate your experience with Google Cloud Platform?

Novice Intermediate Proficient

You should already have your Google Cloud Platform project from the previous lab, so there is no need to create a new project. Sign-in to Google Cloud Platform console (console.cloud.google.com) and select the project from the previous lab.

Download the sample as a zip file and extract it.

Alternatively, you can clone its git repository.

$ git clone https://github.com/GoogleCloudPlatform/getting-started-dotnet.git

Either way, you should have a getting-started-dotnet folder with the following contents.

Double click aspnet\1-hello-world\hello-world.sln. This opens the solution in Visual Studio.

Take a look at WebApiConfig.cs. It includes a simple HelloWorld HTTP handler.

public class HelloWorldHandler : HttpMessageHandler
{
  protected override Task<HttpResponseMessage> SendAsync(
       HttpRequestMessage request,
       CancellationToken cancellationToken)
  {
    return Task.FromResult(new HttpResponseMessage()
    {
      Content = new ByteArrayContent(Encoding.UTF8.GetBytes("Hello World."))
    });
  }
};

In Visual Studio, press F5 to build and run the application. After Visual Studio downloads NuGet dependencies and builds the app, you should see a Hello World message pop up in your browser.

Once you're certain that the app is running locally, press Shift + F5 to stop the application.

It's time to deploy your application to a Windows Server running on a Compute Engine instance.

First, you need to find the external IP of the Compute Engine instance that you deployed in Deploy Windows Server with ASP.NET Framework to Compute Engine. In the Cloud Console, go to Compute > VM Instances, find your instance and note its external IP address.

Now, you will need the Windows username and password you created in the previous lab. If you don't remember it, you can recreate a new Windows username and password under the Connect menu.

In Visual Studio Solution Explorer, right-click on your project and select Publish in the context menu.

In the Publish Web dialog, select Custom as your publish target.

In the New Custom Profile dialog, provide a name for the deployment profile, and click OK.

Fill out your profile as follows.

Server

The external IP address of your Compute Engine instance. This address can be found on the VM instances page in the Cloud Console. The IP address is ephemeral, which is sufficient for our purposes.

Site Name

Default Web Site

Note: The site name you provide here must match the name that appears in IIS Manager on your Compute Engine instance.

Username

The username of the Windows user account you created on your Compute Engine instance.

Password

The password of the Windows user account you created on your Compute Engine instance.

Destination URL

http://<external_ip_of_your_compute_instance>

Note: The destination URL is the address where your page will be accessible after it is deployed.

Click Validate Connection to ensure that the properties are correct.

Because the Microsoft IIS installation in your deployment uses a self-signed certificate by default, you'll see a Certificate Error during the validation process. Check the box to Save this certificate for future sessions of Visual Studio, and click Accept to accept the certificate.

If your configuration is valid, click Settings. Click File Publish Options, and check Remove additional files at destination. This is important for later steps when you publish new web sites to the same Compute Engine instance.

Click Publish to deploy the application. After publishing completes, Visual Studio opens the application in your default web browser.

That's it! Now it's time to clean up the resources you used (to save on cost and to be a good cloud citizen).

You can either delete the instances or simply stop them, although keep in mind that stopped instances can still incur costs related to storage.

Of course, you can also delete the entire project but you will lose any billing setup you have done (disabling project billing first is required). Additionally, deleting a project only stops it from being billed once the current billing cycle ends.

Google Compute Engine is the foundation to Google Cloud Platform's Infrastructure-as-a-Service. As you've seen, it is quite easy to deploy an ASP.NET app to Windows Server on Compute Engine.

What we've covered

Next Steps

License

This work is licensed under a Creative Commons Attribution 2.0 Generic License.

/