June 23, 2016 by Anuraj
C# ASP.NET ASP.NET Core Kestrel
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 :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub