Site icon Ryadel

.NET Core 2 - Change Kestrel default port TCP 5000 (win and linux)

How to Deploy a ASP.NET Core 2 Web Application to Linux CentOS - Tutorial

If you stumbled upon this post, you're most likely trying to install an additional ASP.NET Core 2 Web Application on a Windows or Linux web server using our setup guide or a similar tutorial: since the first one is already there, the default Kestrel listening port  (TCP 5000) is busy, therefore you'll need to change it: however, there aren't many online resources explaining how to do that. That's precisely why we're publishing this article!

Program.cs

The first thing you have to do to change the default Kestrel listening port is to open the Program.cs file in the root of your ASP.NET Core 2 Web Application and add the following line to the default code:

launchSettings.json

The second (and last) thing to do is to open the Properties/launchSettings.json file, locate and change the following line:

That's about it. Once done, publish the web application and add a new Kestrel instance pointing to the <YourProjectName>.dll file (or restart it, if you already created it): the new http listening port (TCP 5002) will be fetched from the updated <YourProjectName>.dll file.

 

Exit mobile version