'localhost port is changing in Visual Studio 2017
Solution 1:[1]
The port may be changing because launchSettings.json is ignored by source control. This common gitignore file, for example, excludes:
**/Properties/launchSettings.json
Visual Studio 2017 stores ASP.NET Core server settings (for both IIS Express and Kestrel) in this file. If it's ignored by source control, it will be regenerated on each machine with a random port. If you check the file in, every machine will use the same server settings.
Solution 2:[2]
Change the port binding in
.vs/config/applicationhost.config
on the node
configuration/system.applicationHost/sites/site[<name>]/bindings/binding[bindingInformation]
from an value like
<binding protocol="http" bindingInformation="*:5000:*" />
to an value like this
<binding protocol="http" bindingInformation=":5000:" />
Solution 3:[3]
You can use UseUrls for that:
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://localhost:5000/")
.Build();
host.Run();
}
}
UPD:
An alternative by passing arguments:
dotnet run --urls http://0.0.0.0:5000
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nate Barbettini |
| Solution 2 | Manuel |
| Solution 3 | Taras Kovalenko |

