Windows v Linux: Compare ASP.NET Core install & hosting

Published: Monday 24 May 2021

Which operating system to host an ASP.NET Core application on? Windows or Linux?

One of the distinct benefits of using ASP.NET Core over ASP.NET is the fact that it has Linux support.

Hosting an ASP.NET Core application allows for more web hosting choice. No longer do we have to rely on Windows hosting.

The main purpose of this is to see what the differences are between the two to make it easier to decide where to host an application.

To find out this, we will compare ASP.NET Core hosting based on the price, the install of the application and the performance.

Pricing

It has been widely known that Linux hosting is cheaper than Windows. But how much cheaper?

For this, we are going to have a look at Windows & Linux pricing for virtual private servers (VPS). The pricing will be based on roughly the same CPU and RAM.

A2Hosting

The first hosting company we will look at is A2Hosting. A2Hosting offer VPS hosting at a fast, reliable web hosting at a fantastic price.

Looking at their unmanaged VPS, a server with 1GB of RAM, 2 vCore processors and 150 GB SSD storage on a one-month rolling contract works out at $7.99 / £5.74 per month*.

They give you a choice of installing either CentOS, Ubuntu or Debian operating systems on to the VPS.

For Linux hosting, this is great. However, they do not offer Windows hosting, so we can't really use this as a comparison.

OVHCloud

In-order to get a fair comparison, we are going to have a look at OVHCloud.

Not only does OVHCloud support a Linux operating system, but it also offers Windows Server.

Looking at a VPS with 1GB of RAM, 2 vCore processors and 40 GB SSD storage on a one-month rolling contract, a Linux VPS works out at $6.00 / £4.00 per month *. This offers a wider range of operating systems, such as Fedora, CentOS, Debian, Ubuntu, Archlinux and FreeBSD.

If we wish to use Windows server, it's an additional $4.50 / £4.00 per month *.

So, as we can see, we are saving a significant amount of money when using Linux hosting.

* Prices correct on 3rd May 2021.

Installation

Next thing we are going to look at is the installation of an ASP.NET Core application.

There are big differences when using Windows to Linux. With Windows, the ASP.NET Core application is installing by using a UI on the operating system.

Linux

With Linux, SSH commands become more of a regular occurrence.

With Ubuntu hosting, a UI can be installed. But, we found with both A2Hosting and OVHCloud hosting, this doesn't come pre-installed. An SSH command would need to be ran for the UI installation.

In-addition, we also found that installing a UI on a low-spec Ubuntu server made the system go really slow and sometimes even stall. We found it was a lot easier to use SSH commands for the application install.

To get an idea on what steps are required for Linux, our article "How To Install An ASP.NET Core In .NET 5 App On Ubuntu 20.04" describes how to do it with SSH commands.

One thing that article doesn't describe is how to set up WebSocket on Apache. An application with SignalR will want to have support for WebSocket for maximum performance.

The Apache configuration file needs to have a rewrite rule added for WebSocket support. When the connection header is set to upgrade, and the upgrade header is set to websocket, the traffic is proxied to the WebSocket (ws) protocol on the ASP.NET Core application.

<VirtualHost *:80>
	ProxyPreserveHost On

	RewriteEngine on
	RewriteCond %{HTTP:Connection} Upgrade [NC]
	RewriteCond %{HTTP:Upgrade} websocket [NC]
	RewriteRule /(.*)    ws://127.0.0.1:5000/$1 [P,L]

	ProxyPass / http://127.0.0.1:5000/
	ProxyPassReverse / http://127.0.0.1:5000/
	 
	ServerName {domain}
	ServerAlias {domain}
	 
	ErrorLog ${APACHE_LOG_DIR}api-error.log
	CustomLog ${APACHE_LOG_DIR}api-access.log common
</VirtualHost>

SignalR is now able to use WebSocket on an ASP.NET Core application in Linux.

Windows

With Windows, we can install IIS using the Control Panel.

In Windows 10, it's a case of going to the Control Panel, selecting Programs and Features and selecting Turn Windows features on or off.

From there, go into Internet Information Services and World Wide Web Services. Tick all the features for installation.

Once IIS is installed, it's time to deploy the application.

Installing the ASP.NET Core runtime and setting appropriate permissions are part of the IIS setup.

You can follow the steps in publishing an ASP.NET Core website to IIS in our article "Four Reasons Why Your ASP.NET Core Application is Not Working in IIS".

This will look at for four things that you need to consider when publishing your ASP.NET Core application to IIS.

Performance

It's hard to measure performance as there are so many factors that can affect performance. Network speed. CPU usage. RAM usage. Database performance.

These factors don't necessarily mean that there is an issue with an ASP.NET Core application.

What we decided to do is to test out Blash in both Windows and Linux.

Blash is a Twitter dashboard that shows real-time tweets in a Blazor WebAssembly application. An ASP.NET Core Web API, Twitter API, SignalR and SQL Server all integrate with Blash, so it's a good application to check that everything is working and performing correctly on both operating systems.

You can check out how it performs with our video below.

Windows or Linux?

Windows or Linux? That's down to personal preference. If you are comfortable with writing SSH commands and want cheap web hosting, it has to be Linux.

However, if you are familiar with Windows and it's UI, then that will be the path to go down.

Regardless of which you choose, the performance should be identical.