How to host your .net application to AWS EC2 Windows Server for free?

Life is full of web applications now. Every other online activity we do over internet has an application interaction. Of course, there are multiple technologies available in the market but then .net has played a great role in terms of backend development. While the developers are still loving development in .net, there are some wonderful .net developers who are developing their own applications and selling them on the markets like codecanyon. Along with development, the developer also focuses on deployment of the application for testing purposes and also for real users. When you are working in corporate, you have all the resources available but when you are working on your own, it will require some investment to host the application. Today, we shall discuss an alternate which can help you to host your .net application for free of cost. So let’s begin.

Where to host for free ?

Yes, that’s the first question. So to host, we have many options but for most of them, you have to loose your pocket money. When I say most of them, it means not all. Yes, we have some free services also available and this free service which we are going to use, is not a cheap company. It is one of the pioneers in the cloud market. So we are going to use AWS EC2 Windows Server. Many of you may already know it but then have challenges to host your application. Today, we shall discuss all those challanges as well.

How to create an AWS EC2 Windows Server Instance ?

You will have to register an account on AWS first. You will be asked for credit card details but do not worry, you will not be charged. They ask for credit card details just to check your authenticity and to ultimately know that you have A POCKET to loose after 1 year because they offer free Honeymoon only for 1 year and after that you become what they wanted you to. So without getting confused, follow the below guide and register.

How to register on AWS

Do not go beyond the registration process in the above article. Just hold on and see below, how to create a windows server instance in AWS. I am assuming that you are on EC2 dashboard.

1. EC2 dashboard has a menu in the left hand side of the screen. You will find a button called ‘Instances’. Click on that.

Instances AWS

2. Then you will see a screen which will show you a button ‘Launch Instance’. Click on that.

Lauch Instance Button

3. You will have to choose the Amazon Machine Image here. In the search bar located, search for ‘Windows server’. You will see the list of windows servers available. Please select the most recent Windows Server Version. In this tutorial, we are selecting ‘Microsoft Windows Server 2019 Base’. Click on ‘Select’ button.

How To Create AWS EC2 Instance And Host .NET Application With IIS

4. Now we come to a screen where we have to choose the type of instance. So in brief, AWS provides different types of configurations according to your requirement and they have different charges. So in this tutorial, we will select ‘t2.micro’ which has 1GB RAM and Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40Ghz Processor. Also AWS provides free storage (meaning the hard disk) of 30 GB with every t2.micro instance. If you want more than 30 GB of hard disk then you will have to pay for it. Anyways we don’t require more than this for our application to run.

5. Once you do this, click on ‘Review and Launch’ located at the bottom.

6. You come to ‘Step 7: Review Instance Launch’ and here you click on ‘Launch’ button located at the bottom.

7. You see a popup which will ask you for key pair creation. So this key pair is replacement of password. On the first dropdown, you select ‘Create a new key pair’ and then in the next field ‘Key pair name’ you can give a key pair name. Click on ‘Download’ and save this file. Remember, this file is confidential and you should keep at a place where no one can access it. You can upload it at your google drive.

Create a new key pair

8. Click on ‘Launch Instances’. You will see a screen like this.

Launching Status of AMI AWS

You have finally created a Amazon Machine Image featuring Windows Server 2019. Now we will see, how we can make use of this machine as Remote Desktop. So this remote desktop is exactly like that remote machine which we have in corporate for development of code. Companies generally ask their employees to work on RDP client so that no code can be transferred anywhere.

How to connect to AWS EC2 Windows Server using RDP Client?

Once again, go to the EC2 Dashboard and go to the ‘Instances’. Once you are there, you will see an instance running. Just click on the checkbox located against the instance and then on ‘Connect’ button located above. You will see something like below.

How To Create AWS EC2 Instance And Host .NET Application With IIS

Click on ‘RDP Client’ and you will see the above options. Click on ‘Download remote desktop file’. This will download a RDP file for you to connect to your remote machine. Along with this RDP file, we also need the admin password which will be asked at the time of connecting via RDP. So click on ‘Get Password’. You will have to upload the key pair file which you have downloaded in order to get the password. Once you get the password, save it.

Now click on the RDP file you have downloaded. It will ask you for password. Give your password which you have just saved. That’s all. You may receive a warning while connecting. Just click on ‘yes’ and go ahead. You will now be connected to Remote Desktop (A kind of new computer which is remotely located).

We will set the IIS server on Remote Desktop now.

How to enable IIS server on AWS EC2 Windows Server?

1. Search for ‘Server Manager’ by search button on task bar. Click on it.

2. Click on ‘Add roles and features’ located on the dashboard.

3. Click ‘Next’.

4. Select “Role-based or feature-based installation” and click “Next”.

5. Click on “Select a server from the server pool”, then select your server and click “Next”.

6. Check on “Web Server (IIS)” from “Server Roles” list, select the below features and click “Next”.

IIS Web Server Features
IIS Web Server Features
IIS Web Server Features
IIS Web Server Features

7. Select the .net features like .NET Framework 3.5 Features and ASP.NET 4.7 from the list.

IIS Web Server Features

8. Click on ‘Next’.

9. Click “Install” and wait until the installation is complete. It will show more features in the list. The screen below shows less number of features because they are already installed for me. Click on ‘Close’.

IIS Web Server Installation

How to deploy the .net application in the AWS EC2 Windows Server ?

So now comes the final goal. We want to deploy the application to the server. Before deploying the application, we shall do one thing so that we can enable Internet Explorer to work properly. By default, IE is enabled with high security so that you can not access any website and you can not download anything. Let’s remove this high security to access the internet and enable the download. Look at the below screenshot.

Click on the ‘On’ button highlighted against ‘IE Enhanced Security Configuration’. You will see a dialog box like below.

Click on ‘Off’ for Administrators. That’s it. You are good to go now.

So there are two ways one is using Web Deploy Package and other one is directly hosting the application.

As of now, we are using the direct way of hosting the application whereby you can directly put your application in a folder and create a website associated with that folder.

  • Go to C:\ (C drive)
  • Then to intepub folder
  • And finally to wwwroot folder. Under this folder, you can create a folder where you can all your project publish files.

If you don’t have any application, you can download a sample from here and follow the below steps.

1. Go to IIS Manager.

How to add a website to IIS

2. Add a website.

How to add a website to IIS

3. Locate the folder and give a Sitename. Here we are naming it ‘testsite’ and the folder we have named as ‘testapp’.

How To Create AWS EC2 Instance And Host .NET Application With IIS

Go to your browser and type http://localhost, If everything is alright, you should see a screen like below.

How To Create AWS EC2 Instance And Host .NET Application With IIS

So We have hosted a sample .net web application on AWS EC2 Windows Server. Sometimes some people may face some challenges while running the application. This may be because of some missing modules required by application. Try installing the below modules by downloading them and also if you know any particular modules required then please install them as well.

ASP.NET Core Runtime 3.1.14

Download Here

IIS URL Rewrite

Download Here

This way, you will be able to run the application from inside the Remote Desktop but what if you want to run the same application from outside. You just have to configure two inbound rules under EC2 Instance Security Group.

1. Go to the AWS EC2 Dashboard again and click on the ‘Security Groups’ located at the left.

2. You will see security groups like this.

3. Select the first security group and click on ‘Actions’ located above. From the dropdown, click on ‘Edit inbound rules’.

4. Edit the inbound rules like below. Note that, you just have to add rule for HTTP and HTTPS. Rule for RDP will be already there. You can make use of ‘Add rule’ button for adding more.

This will allow the traffic from HTTP and HTTPS with no boundaries. Now you should assign an Elastic IP to your instance because public IP associated with this instance is changed if you stop and start the instance in future. For allocating and assigning an Elastic IP, you should follow below link.

How to create a blog for absolutely free

After following this guide, you may try to browse the Elastic IP on your browser and you will see your application up and running. Also if you have a domain and you want to connect it with this IP, you can follow the below guide.

How to point your domain to AWS EC2 Elastic IP

This completes this tutorial where we have learned to deploy a .net web application with AWS EC2 Windows Sever. If you still have any doubts, you may ask them in comment section.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.