1. Overview
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. You might want to complete that lab first.
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
- How to create a simple ASP.NET app.
- How to run the ASP.NET app locally in Visual Studio.
- How to deploy and run your ASP.NET app to a Windows Server on Compute Engine.
What you'll need
- A browser, such Chrome or Firefox.
- Visual Studio 2013 or later installed.
- Familiarity with the .NET Framework and the C# language.
- A Windows Server with ASP.NET Framework running on Compute Engine along with a Windows username and password from the Deploy Windows Server with ASP.NET Framework to Compute Engine codelab.
How will you use this tutorial?
How would rate your experience with Google Cloud Platform?
2. Setup and Requirements
Self-paced environment setup
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.
3. Download the ASP.NET app
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.
4. Run the application locally
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.
5. Deploy Windows Server with ASP.NET Framework
In this section, we'll learn how to create a new Google Compute Engine virtual machine instance with Windows Server and ASP.NET Framework installed using Cloud Marketplace from Google Cloud Console.
Log into Google Cloud Console
Navigate to Google Cloud Console from another browser tab or window, to https://console.cloud.google.com. Use the login credentials you have set up when you signed up for Google Cloud Platform or those given to you by the lab proctor.
Navigate to Cloud Marketplace
In Google Cloud Console, click the Menu icon for Products & services in the top left of the screen:
Then navigate to Cloud Marketplace
Search for ASP.NET Framework
Type ASP.NET to search for ASP.NET Framework and then click on the result box below.
Launch on Compute Engine
In the next screen, click on Launch on Compute Engine.
There are many parameters you can configure when creating a new instance. Let's use the following:
Name |
|
Deployment Name |
|
Zone |
|
Machine Type |
|
Windows Server OS Version |
|
Boot Disk Type |
|
Disk size in GB | 100We're using the default of 100GB, but you may adjust it to more or less depending on your needs. |
Firewall |
|
Click on Deploy to create the new virtual machine instance with Windows Server and ASP.NET Framework! This will take you to a new page where you can see the progress.
Once finished, go to Compute Engine from the menu on the left and then select VM Instances. You should see the new virtual machine in the VM Instances list.
If you click on External IP, you should also see the default IIS website served from the instance.
Note that you can also Remote Desktop (RDP) into the machine but we need to create a Windows user and password first.
6. Create a Windows user and password
To create a Windows user and password, select Create or reset Windows password.
This will open a new window where you can create a user. Keep the default and select Set. After a few seconds, you should have a New Windows password dialog with the newly created password. Make a note of the password, as you will need it in the next section.
7. Deploy the application to your Windows Server on Compute Engine
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 step.
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 |
|
Site Name |
|
Username |
|
Password |
|
Destination URL |
|
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.
8. Cleanup
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.
9. Congratulations!
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
- How to create a simple ASP.NET app.
- How to run the ASP.NET app locally in Visual Studio.
- How to deploy and run your ASP.NET app to a Windows Server on Compute Engine.
Next Steps
- Learn more about Windows on Google Cloud Platform.
- Learn more about .NET on Google Cloud Platform.
- Learn more about SQL Server on Google Cloud Platform.
- Learn more about Cloud Tools for Visual Studio.
- Learn more about Cloud Tools for PowerShell.
License
This work is licensed under a Creative Commons Attribution 2.0 Generic License.
/