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!
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:
public static IWebHostBuilder CreateWebHostBuilder(string args) =>
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.