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:
1 2 3 4 |
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .UseUrls("http://localhost:5002"); |
launchSettings.json
The second (and last) thing to do is to open the Properties/launchSettings.json file, locate and change the following line:
1 2 3 4 5 6 7 8 |
"<YourProjectName>": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "https://localhost:5003;http://localhost:5002", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } |
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.