Posted by Anuraj on Thursday, June 23, 2016
This post is to about configuring Kestrel URLs. Prior RC2, you can configure the Kestrel URLs in the project.json using –server.urls option, inside the Web command section. And if nothing specified, it will use the default binding http://localhost:5000. As of RC2 we have a new unified toolchain (the .NET Core CLI) and ASP.NET Core applications are effectively just .NET Core Console Applications, commands are no more relevant. You can modify the main method to change the URLs using the UseUrls method.
But I am not a fan of hard coding the URLs. Fortunately it’s still possible to load the Kestrel configuration from an external file. Create hosting.json file in the root directory, and add the URLs inside it like this.
And you can load the configuration using AddJsonFile method, and apply it using the UseConfiguration method.
Similar way you can configure the URLs from command line as well as Environment variables.
And to use the ConfigurationBuilder class, you require “Microsoft.Extensions.Configuration” reference in the project.json file.
Happy Programming :)