.NET Core 2 - Change Kestrel default port TCP 5000 (win and linux) How to change default Kestrel listening port (TCP 5000) in a ASP.NET Core 2 Web Application on a Windows or Linux web server

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.

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

One Comment on “.NET Core 2 - Change Kestrel default port TCP 5000 (win and linux) How to change default Kestrel listening port (TCP 5000) in a ASP.NET Core 2 Web Application on a Windows or Linux web server

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

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