The default configuration file used by the Kestrel server, hosting.json . The name has been changed several times in different beta versions. If you are now using project.json with the following "command" section
"commands": { "web": "Microsoft.AspNet.Server.Kestrel" }
then when starting the server from the command line on
dnx web
the hosting.json file will be read. File
{ "server.urls": "http://0.0.0.0:5000" }
configure the server to listen on 5000 on each IP4 address. Configuration
{ "server.urls": "http://::5000;http://0.0.0.0:5000" }
will tell you to listen to 5000 on both IP4 and IP6.
Alternative configuration files can be specified using the ASPNET_ENV environment ASPNET_ENV or by using --config myconfig1.json (or config=myconfig1.json ). For example, you can use
SET ASPNET_ENV=Development
and create a hosting.Development.json file with a specific configuration. Alternatively, you can use project.json with
"commands": { "web": "Microsoft.AspNet.Server.Kestrel" "webProd": "Microsoft.AspNet.Server.Kestrel --config prod.json" }
and start the server using
dnx webProd
I need to be further reminded that you may need additional listening and registration (to run dnx web ). This is necessary due to the firewall and local security when listening on new TCP / HTTP ports. Something like below should do local registration and listening for 5000 ports for all (IPv4 and IPv6):
netsh http add iplisten ipaddress=0.0.0.0:5000 netsh http add iplisten ipaddress=::5000 netsh http add urlacl url=http://+:5000/ user=\Everyone
To be more secure, you can configure the above configuration to provide minimal rights.
UPDATED: Thanks @BlaneBunderson. You can use * instead of an IP address (for example, http://*:5000 ) to listen on any IP4 and IP6 addresses from any interface. You need to be careful not to use http://*:5000;http://::5000 , http://::5000;http://*:5000 , http://*:5000;http://0.0.0.0:5000 or http://*:5000;http://0.0.0.0:5000 , because for this you will need to double-register the IP6 :: address or IP4 address 0.0.0.0 .
Matches Ad
Technically, any hostname that is not โlocalhostโ or a valid IPv4 or IPv6 address will result in Kestrel binding to all network interfaces.
I think that behavior may change in the future. Thus, I would recommend using only the forms *:5000 , 0.0.0.0:5000 and ::5000 to register any IT address.
UPDATED 2: Changes in ASP.NET Core RC2 (see announcement ) default load behavior. You need to make changes to Main to load the settings from hosting.json and command line options. Below is an example of use
public static void Main(string[] args) { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("hosting.json", optional: true) .AddEnvironmentVariables(prefix: "ASPNETCORE_") .AddCommandLine(args) .Build(); var host = new WebHostBuilder() .UseUrls("http://*:1000", "https://*:1234", "http://0.0.0.0:5000") .UseEnvironment("Development") .UseConfiguration(config) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); }
The above code uses three bindings: "http://*:1000" , "https://*:1234" , "http://0.0.0.0:5000" by default instead of using the default 5000 ports by default (more precisely , use http://localhost:5000 ). The .UseConfiguration(config) call is made after .UseUrls . Thus, the configuration loaded from hosting.json or the command line overwrites the default settings. If you delete the line .SetBasePath(Directory.GetCurrentDirectory()) , then hosting.json will be loaded from the same directory where the application dll will be compiled (for example, bin\Debug\netcoreapp1.0 ).
You can use execution, for example
dotnet.exe run --server.urls=http:
to overwrite the default settings (from UseUrls ) and the settings from the "server.urls" hosting.json property, if they exist.
In the same way, you can overwrite the ULR settings by setting the environment variable.
set ASPNETCORE_SERVER.URLS=http:
then by default running the application using dotnet.exe run will use http://localhost:12541/ to bind.
You can find an example of using HTTPS bindings here .