.NET Core Development: A Practical Example

19-01-2024 05:08:57

.NET Core is an open-source, cross-platform framework developed and maintained by Microsoft Corporation. It is used to develop a variety of high-performance applications. In this article, I demonstrate how to install .NET Core 3.1 on a CentOS 7 cloud server and deploy a complete .NET Core application.

Installing .NET Core

Before installing .NET Core, it's necessary to register Microsoft's key and repository:

rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm

Next, we install the .NET Core SDK and the .NET Core runtime:

yum install dotnet-sdk-3.1
yum install aspnetcore-runtime-3.1
yum install dotnet-runtime-3.1

Sample Application

Creating a Console Application

dotnet new console -o helloworldApp
cd helloworldApp

Run the application:

dotnet run

The output is as follows:

Hello, world!

Creating a Web Application

dotnet new razor -o myfirstwebapp
cd myfirstwebapp

Run the application:

dotnet run

Then, visit http://IP:5000 to view the content of the Web application. You can stop the Web application using the shortcut Ctrl + C.

Finally, publish with the following command:

dotnet publish

Configuring the Firewall

To ensure proper access to the Web application, it is essential to open ports 80 and 443 on the firewall. The specific setup is as follows:

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload

With this, we have completed the development and deployment of our .NET Core application, and it can now be accessed directly using the cloud server's IP address.