How to deploy an ASP.NET app to the cloud from Visual Studio Web Deploy – Comparing Azure vs AWS vs Google Compute

Introduction

So, you’re a Rockstar developer and you’ve constructed an app that is primed and ready to be the next big thing. All that stands between you and millions of users is deploying it to the cloud. While you’ve narrowed your choices to Microsoft Azure, Amazon Web Services (AWS), or Google Compute, you just aren’t sure about where to park your creation for the long haul. After all, you expect to be publishing new features and updates daily for quite some time. The future home of your masterpiece can’t slow you down on your quest to conquer the computing universe! You’ve done your pricing research and all three options are comparable, so really the decision comes down to first time configuration ease, first time deploy time, subsequent deploy times, and any other perks that might save you steps in the future as this juggernaut scales.

Well my friend, this guide was written for you!

Prerequisites

Since you probably aren’t going to hand over the source code to your ultimate creation, for purposes of demonstration, we will call upon our old reliable and trusty friend, “Hello World”, written in C#, ASP.NET Core, and utilizing Visual Studio 2015.

This guide assumes you have accounts setup at Azure, AWS and Google Compute. For Azure, you’ll want to install the latest Azure SDK for Visual Studio 2015. For .NET Core, make sure you have installed Visual Studio Update 3 or greater. It’s also a good idea to do all of your updates for Visual Studio under Extensions and Updates.

Azure

First, we will deploy our web app to Microsoft Azure. One nice thing about deploying to Microsoft’s cloud service when using Microsoft’s development studio is that the two are very nicely integrated. The first advantage that Azure has over any other platform is in configuration. When you open Visual Studio to build your web app, click “New Project…”:

New Project

Next, select Templates->Visual C#->.NET Core->ASP.NET Core Web Application (.NET Core).  Uncheck “Add Application Insights to project” and give your project the name “HelloWorldAzure”:

NewProject_HelloWorldAzure

On the next screen, select “Web Application” and you’ll see in the bottom right quadrant of the screen, “Host in the cloud” is checked.  This is great, because this helps us configure our cloud deployment without having to bounce between interfaces.

Web Application

After clicking “OK”, the following screen loads. You’ll notice everything will preselect and fill.  A unique name will be generated for your Web App Name. You can change this to whatever you want it to be as long as it is unique. Your subscription will preselect from the list, however if you have multiple subscriptions you’ll need to select the correct one. If already you already have a Resource Group and App Service Plan created in the same region, they will preselect.  If not, you can select the correct one(s) or create new ones by clicking “New…”. For this example, we’ll create a new resource group and app service plan.

Create App Service

After I click “New…” on Resource Group, it asks for me to give the Resource Group a new name.  I’ll choose HelloWorldAzureResourceGroup.  After I click “New…” on App Service Plan, I get the following dialogue prepopulated with all of the options I need, so I’ll click “OK”.

Configure App Service.png

Now that you see these changes to the Create App Service dialogue:

App Service Resource Group

I now click the Create button and get a familiar progress dialogue:

Creating Project HelloWorldAzure

At the completion of the progress dialog, our project is now created. To make this a real “Hello World” web app, navigate to the Index.cshtml view under Home and replace the HTML in the view with the following and save.

<h1>Hello World!</h1>

Now, it’s time to get our project deployed to Azure. First, right click on the project and click “Publish…”.

Publish to Azure

You’ll notice right away that all of the setup work took and the project is ready to publish.

Publish to Azure Dialog

As long as you don’t need to reconfigure you are safe to click Publish. After waiting a minute or so, your environment will be created in Azure and your project will be deployed. You’ll see Publish Succeeded in the bottom left corner of your Visual Studio and a browser will open with your website in it deployed on an azurewebsites.net domain.

Hello World Browser View

There are many more Azure features to explore, but that summarizes the basics of getting a project published to the cloud.

AWS and Google Compute

To get a “Hello World” project ready for AWS or Google Compute, we need to bypass all of the Microsoft Azure platform integration during project creation. First start by reading the beginning of the Azure guide above, but name the project HelloWorld instead of HelloWorldAzure and when prompted to “Host in the cloud” uncheck that box.

Host in Cloud disabled

I now click the OK button and get a familiar progress dialogue:

Creating Project HelloWorld

At the completion of the progress dialog, our project is now created. Just like in our Azure setup, to make this a real “Hello World” web app, navigate to the Index.cshtml view under Home and replace the HTML in the view with the following and save.

<h1>Hello World!</h1>

At this point, our project is now ready to deploy, but the process is different for each platform, while the overall process is going to be the same. First, we need to create a compute instance on each platform. Next, we need to configure that instance to receive our web application. Then we configure our application for deploying to that instance. Finally, we deploy to the instance by using the Publish wizard like we did in the Azure example, but our new publish profile will target our compute instance and not Azure.

AWS

The way we are going to get our application to AWS is to build an AWS EC2 instance and configure it for Web Deploy. To do this, we need to sign into our AWS Console. From here, click Services->EC2.

AWS EC2

Click the blue “Launch Instance” button:

AWS Launch Instance

Scroll about halfway down the list and select:

AWS Windows Server Selection

By default, the AWS EC2 wizard will select t2.micro. This is fine for our purposes, but you can pick whichever computing power you think you’ll need here. Remember that you are building a virtual machine to run as a web server, so it needs to be able to support your application. In the future, you can tear it down and replace it, but these are considerations you’ll want to think through.

AWS Created Server Progress

Next, you’ll need to configure your webserver. Click “Next: Configure Instance Details”.

AWS Config Inst Button

Here you can configure many details about your web application, including number of instances and other details. For our purposes, we will leave the defaults and click “Next: Add Storage”.

AWS Add Storage Button

Again, the defaults here are fine for our purposes, but you might want more or less storage, more volumes, different speeds, etc.. These are all things to consider. Click “Next: Add Tags”.

AWS Add Tags Button

On this screen you can assign Tags to your EC2 instance. Tags are the way in AWS to help you identify your resources and categorize them for different purposes. For our example, click “Next: Configure Security Group”.

AWS Config Sec Group Button

Finally, a screen we need to affect to get our app working. Since we are building a web server, we need to allow HTTP traffic at minimum, but we’ll also add web deploy traffic too. If you are going to configure your application for SSL/TLS or other ports and traffic, you’ll have more work to do here.

First, you’ll notice RDP is added already. This rule allows you to be able to use Remote Desktop to remotely administer your server. Leave this in there, we’ll need that access later, but change the Source to Anywhere.

Next, click “Add Rule” to add our HTTP rule. Scroll to HTTP in the drop down and that is all we need. It automatically sets up port 80, which is the default HTTP port. Again, use Source Anywhere.

For web deploy, click “Add Rule” and leave it as Custom TCP Rule. For the Port Range, pick 8172, which is what web deploy listens on. You guessed it, set the Source to Anywhere as well.

At this point, your screen should look like:

AWS Config Sec Group Screen

Click the blue “Review and Launch” button. On the next screen you can review what you have configured. Once you are satisfied, you can click the blue “Launch” button.

AWS Review Instance Screen

You’ll now be prompted to “Select an existing key pair or create a new key pair”. Once you’ve created a key pair, you can select it, but since this is our first time running through, we’ll “Create a new key pair”. To do so, give the key pair a name and click “Download Key Pair” to download the PEM file. You need to do this, because you won’t be able to do it later. You’ll need this file to be able to access your instance after it is created.

AWS Select Key Pair

Once you download your PEM file and store it in a safe place, click the blue “Launch Instances” button. It’ll take a few minutes, but your instance will be created. Click the blue “View Instances” button at the bottom of the screen.

AWS View Inst Button

Next you’ll see your instance “Initializing” on the next screen:

AWS Inst Init Screen

Once the Status changes from “Initializing” to “2/2 checks passed”, your instance is ready to connect to and finish the configuration.

AWS Inst Init Passed Screen

At this point, we will RDP to the server. To do this, right click on the instance and click “Connect”.

AWS Connect Inst Screen

Click “Download Remote Desktop File”. The file will save by default to your downloads on your computer. Next, click “Get Password”. Now the PEM file we downloaded comes into play. You can either copy and paste the contents of the file into the next dialog or browse to the file and upload it. Either way, once you have it in the text box on the screen, click “Decrypt Password”.

AWS Connect Inst Password Screen

Now you can get your password to use for the Administrator account. Open the RDP file and connect using this information. You’ll be prompted to accept the security certificate. Click “Yes”.

Because both AWS and Google Compute are so similar once you connect to the server to configure it, I’ll explain how to build a Google Compute instance next. You can skip to the Configure IIS headling if this doesn’t interest you.

Google Compute

To create a Google Compute instance, log in to your Google Compute Console. Click “Create Project” from the drop down at the top. You will be prompted to give your project a name. We’ll call this project “Hello World”. Google Compute will assign a project ID that is unique to this project.

GC New Project

Click “CREATE” and after about a minute you’ll be taken to the dashboard for your project.

GC Dashboard

Click the hamburger menu (GC Hamburger) at the top left and click:

GC Cloud Launcher Button

From the Cloud Launcher, scroll to OS and click:

GC Server Selection

Then on the next screen click the blue “Launch on Compute Engine” button.

GC Server Selection Win

You’ll now be prompted to select your billing account.

GC Billing Account

Select it from the list and click “SET ACCOUNT”. You are now in the Google Compute Engine and your server is initializing:

GC VM Instances

Wait about another minute or so and you’ll be prompted to complete the setup. From this screen, you can change any settings you want, but for this example, check Allow HTTP traffic. If you were configuring this server for SSL/TLS you’d want to also check Allow HTTPS traffic too.

GC Firewall

Once you’ve done this, click the blue “Create” button.

GC You be billed

After clicking, you’ll be taken back to the VM Instances page. Creating your new server takes a few minutes. You can watch and wait on this screen.

GC Server building

Your sever is configured when it gets the green checkmark:

GC server configured

Now that our server is created, we need to open up a port in the network to allow Web Deploy. Click on the server name to take you to the edit screen. Scroll down to the network section and click the “default” link.

GC more firewall

Scroll down to your firewall rules and click “Add firewall rule”.

GC FW rules

Fill out your rule just like this:

GC create FW rule

When you are finished, click the blue Create button. Then click the back arrow 2 times to get you back to the VM Instances screen.

At this point, we need to configure a Windows account, so click on the server name to take you to the edit screen. Click on “Create or reset Windows password” at the top of the page.

GC RDP pass
GC set win pass

Click “SET” and on the next screen copy the password from the dialog and click “CLOSE”.

GC new win pass

Now that you have a windows account, you need to download the RDP file to connect to the server. To do this, click the RDP dropdown on the VM instances edit screen for your server. Then click “Download the RDP file”.

GC download rdp file

You may be prompted to login to your Google account again, but afterwards the file will download to your Downloads folder. Move this file to another location and open it. Use the username and password you created in the previous steps. You’ll be prompted to accept the security certificate. Click “Yes”.

Configure IIS

Now that you have your compute instance created in either AWS or Google Compute and you have logged into your server, you need to configure your server to host your website. First, you need to go to Server Manager and click on Local Server.  From the Manage menu, select “Add Roles and Features”. This opens the Add Roles and Features Wizard.

Server Config IIS

From here, click Next, then select Role-based or feature-based installation and click Next. On the next screen, select “Select a server from the server pool” and click Next.

From this screen you’ll need to select “Web Server” then click Add Features.

Server Select Roles
Server Select Roles dialog

After that, click Next. On the next screen select ASP.NET 4.5 under .NET Framework 4.5 Features. We’ll install .NET Core on a different step.

Server Select Roles net

Click Next. Then click Next on the following screen. Then you will have the Web Server installation tree. Click Next on this screen. Then click Install on the following screen.

Server Select Roles confirm

Wait about one minute and the installation will finish.  Click Close.

Server Select Roles complete

Next we need to get ASP.NET Core installed, as well as Web Deploy. Open Internet Explorer and navigate to https://www.microsoft.com/web/downloads/platform.aspx to download Microsoft Web Platform Installer.

After you install the Web Platform Installer, it’ll open with a screen like this:

Server WPI.png

Search for Web Deploy 3.6 for Hosting Servers:

Click Add, then click Install, then click “I Accept”.

After a few minutes, you’ll see this screen and see that it succeeded.

Server WPI complete.png

Click Finish, then click Exit to exit the Web Platform Installer.

Now open Internet Explorer and download and run the latest ASP.NET Core Server Hosting Bundle installation from https://go.microsoft.com/fwlink/?linkid=837808.

Follow the wizard to install. After the installation is complete, reboot your server.

Deploy to the Cloud

Regardless of if you chose AWS or Google Compute, now we need to configure our application to deploy to our compute instance.

In Visual Studio, right click on the project name and click Publish.

web deploy publish

This opens the Publish wizard. Select Custom and then give your publish profile a name. I’ll use CloudDeploy as mine.

web deploy publish name.png

Click OK and for Publish method pick Web Deploy.

web deploy publish server info

For Server, put in the IP address or host name of the compute instance. For “Site name” put in Default Web Site. For “User name” put in the user name (probably Administrator) and for Password put in the password. Check “Save password” and click “Validate Connection”.

At this point you will have to validate a certificate for Web Deploy. Be sure and check “Save this certificate for future sessions of Visual Studio”.

web deploy publish cert error.png

If everything went well so far, you’ll see:

web deploy publish cert error validate

Click Next. On this screen expand “File Publish Options” and check “Remove additional files at destination”.  This will be useful when publishing updates to your application so you aren’t left with remnants of previous deployments.

web deploy publish remove old

Now click Publish.  The publish will most likely error with an error code of ERROR_CERTIFICATE_VALIDATION_FAILED. This is expected because of the untrusted certificate issued by the compute instance. In your Solution Explorer, find your publish profile file with the .pubxml file extension. Open this, and add the following on a new line before the </PropertyGroup> tag.

<AllowUntrustedCertificate>True</AllowUntrustedCertificate>

Save the file, close it, right click on your project and click Publish again. Now when you click the Publish button the publish will succeed. Open your IP address or server host name in your browser and you should see your application:

Hello World Browser View not azure

Voila! You’re done! You have succeeded in building a web server on your platform of choice and deploying your application to the cloud.

Conclusion

Congratulations! You are now an expert on deploying your ASP.NET Core web application to Microsoft Azure, AWS, and Google Compute. As you can see, all three systems, with the proper configuration can accept your web application from Web Deploy and deploy and run with ease.

Comparing the different platforms, there is really not very much difference in configuration between AWS and Google Compute. They both are very powerful, and give you good wizards to walk through the setup on their websites. The only downside is having to RDP to the server to configure it, but these things can be scripted and probably should be scripted using a system like Chef or Jenkins to reduce user error.

Microsoft Azure seems to be the most direct way to deploy, but you’d expect that since you are using Microsoft Visual Studio to configure and deploy the application. Azure, from it’s tight integration, doesn’t give you the server level granular control right out of the box using an App Service, like we had on the other two platforms. Azure does have this capability using Web Roles or just building a VM and installing .NET Core and Web Deploy on the server like we did on the other platforms. Likewise, there are volumes of Chef recipes or different scripts online to build and tear down AWS or Google Compute servers.

Finally, your choice should come down to cost, preference and possibly geography, although all three of these platforms have great worldwide geographical coverage. You really can’t lose, so get out and take advantage of what ASP.NET Core and the cloud have to offer in rapid development, continuous integration and scale! Happy coding!

Advertisement