- read

How to Host Your ASP.NET Core Web App on DigitalOcean for Free (or Almost 200$ Credit)

NinjaCoder 34

How to Host Your ASP.NET Core Web App on DigitalOcean for Free (or Almost 200$ Credit)

NinjaCoder
Level Up Coding
Published in
7 min read2 days ago

--

Start free with a 200$ credit at DigitalOcean

Photo by Marvin Meyer on Unsplash

Do you have an ASP.NET Core web app that you want to host on a reliable and scalable cloud platform? Do you want to save money and avoid paying for expensive hosting services? Do you want to learn how to deploy your app to DigitalOcean droplets using Visual Studio and PuTTY?

If you answered yes to any of these questions, then this article is for you. In this article, I will show you how to host your ASP.NET Core web app on DigitalOcean for free (or almost free) using a simple and easy method.

What is DigitalOcean and Why Should You Use It?

DigitalOcean is a cloud computing platform that provides various services such as virtual machines (droplets), storage, networking, databases, and more. You can use DigitalOcean to host your web apps, websites, blogs, e-commerce stores, and anything else that you can think of.

Some of the benefits of using DigitalOcean are:

  • It is fast, reliable, and secure. Your app will run on high-performance servers with SSD storage and 99.99% uptime.
  • It is flexible and scalable. You can choose from different droplet sizes, regions, and operating systems. You can also resize, reboot, or destroy your droplets anytime.
  • It is affordable and transparent. You only pay for what you use, with no hidden fees or contracts. You can also monitor your usage and billing from the dashboard.
  • It is easy to use and learn. You can create and manage your droplets using a simple web interface or a command-line tool. You can also find plenty of tutorials, guides, and documentation on their website.

How to Get $200 in Credit to Try Out DigitalOcean

If you are new to DigitalOcean, you can get $200 in credit to try out their services for free for 60 days. All you have to do is sign up using my sign-up link. This will give you enough credit to create up to 10 droplets with 1 GB of RAM each.

You can use this credit to host your ASP.NET Core web app or any other project that you want to try out on DigitalOcean. You can also use this credit to learn how to use DigitalOcean’s features and tools.

But hurry up, this offer is only valid for a limited time. So don’t miss this opportunity and sign up now using my sign-up link.

How to Deploy Your ASP.NET Core Web App to DigitalOcean Droplets

Now that you have signed up for DigitalOcean and got your $200 in credit, you are ready to deploy your ASP.NET Core web app to DigitalOcean droplets. This process consists of four main steps:

  • Step 1: Publish your ASP.NET Core web app to a folder using Visual Studio.
  • Step 2: Transfer your published folder to your droplet using PuTTY.
  • Step 3: Install .NET Core runtime on your droplet using PuTTY.
  • Step 4: Run your ASP.NET Core web app on your droplet using PuTTY.

I will explain each step in detail below.

Step 1: Publish Your ASP.NET Core Web App to a Folder Using Visual Studio

The first step is to publish your ASP.NET Core web app to a folder on your local machine. This will create a set of files that you can copy to your droplet later.

To do this, follow these steps:

  • Open your ASP.NET Core project in Visual Studio.
  • Right-click on the project name in the Solution Explorer and select Publish.
  • In the Publish window, select Folder as the target and click Create Profile.
  • Choose a location for the folder and click Save.
  • Click Publish to start the publishing process.

You should see a message saying that the publishing was successful. You can also check the folder location to see the files that were created.

Here is an example of how the publish window looks like:

Step 2: Transfer Your Published Folder to Your Droplet Using PuTTY

The next step is to transfer your published folder to your droplet using PuTTY. PuTTY is a free and open-source SSH and telnet client that you can use to connect to your droplet and execute commands.

To do this, follow these steps:

  • Open PuTTY and enter your droplet’s IP address in the Host Name field.
  • In the left pane, expand SSH and select Auth.
  • Click Browse and select your SSH key file that you generated earlier.
  • Click Open to start the connection. You may see a security alert asking you to confirm the connection. Click Yes to continue.
  • Enter your username (usually root) and press Enter. You should see a welcome message from DigitalOcean.
  • Type cd /var/www/html and press Enter. This will change your current directory to the web root of your droplet.
  • Type mkdir app and press Enter. This will create a new folder called app for your web app.
  • Type exit and press Enter. This will close the connection.

Now, you need to transfer the files from your local folder to the remote folder using PuTTY’s file transfer utility called PSCP.

To do this, follow these steps:

  • Open a command prompt on your local machine and navigate to the folder where you published your web app.
  • Type pscp -r -i "path\to\your\ssh\key\file" * root@your_droplet_ip:/var/www/html/app and press Enter. This will copy all the files from your local folder to the remote folder using your SSH key for authentication. You may see some progress messages as the files are being transferred.
  • Wait until the transfer is complete.

Here is an example of how the command prompt looks like:

Step 3: Install .NET Core Runtime on Your Droplet Using PuTTY

The third step is to install .NET Core runtime on your droplet using PuTTY. .NET Core runtime is required to run your ASP.NET Core web app on Linux.

To do this, follow these steps:

  • Open PuTTY again and connect to your droplet as before.
  • Type wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb and press Enter. This will download a package that contains Microsoft’s public software signing key and repository information for Ubuntu 20.04 (the operating system of your droplet).
  • Type sudo dpkg -i packages-microsoft-prod.deb and press Enter. This will install the package on your droplet.
  • Type sudo apt-get update and press Enter. This will update the list of available packages on your droplet.
  • Type sudo apt-get install -y apt-transport-https and press Enter. This will install a package that allows the use of HTTPS for package downloads.
  • Type sudo apt-get update and press Enter. This will update the list of available packages again.
  • Type sudo apt-get install -y dotnet-runtime-5.0 and press Enter. This will install the .NET Core runtime version 5.0 on your droplet.

Here is an example of how PuTTY looks like:

Step 4: Run Your ASP.NET Core Web App on Your Droplet Using PuTTY

The final step is to run your ASP.NET Core web app on your droplet using PuTTY. You can use the dotnet command to launch your web app and make it accessible on the web.

To do this, follow these steps:

  • Open PuTTY again and connect to your droplet as before.
  • Type cd /var/www/html/app and press Enter. This will change your current directory to the folder where you copied your web app files.
  • Type dotnet YourWebAppName.dll and press Enter. This will start your web app and listen for requests on port 5000 by default. You should see a message saying that the web app is running.
  • Open a web browser on your local machine and enter http://your_droplet_ip:5000 in the address bar. You should see your ASP.NET Core web app running on your droplet.

Congratulations! You have successfully hosted your ASP.NET Core web app on DigitalOcean for free (or almost free).

Conclusion

In this article, I showed you how to host your ASP.NET Core web app on DigitalOcean for free (or almost free) using Visual Studio and PuTTY. I hope you found this article helpful and informative.

If you have any questions or feedback, please feel free to leave a comment below.

And don’t forget to sign up for DigitalOcean using my sign-up link to get $200 in credit to try out their services for free for 60 days.

Happy coding!