I would like to connect to my Kestrel server with ASP.NET 5 application hosted on it from another PC in the same network. Is it possible? I can ping my computer from cmd, but I get 'Connection timed out' when I try to connect from a web browser (I type this: "http://{my_kestrel_ip}:5000/").
In your project folder you should have a file called hosting.ini
. In that file by default you should have something like this:
server=Kestrel
server.urls=http://localhost:5000
You need to make the HTTP server listen on your public IP address as well as localhost. To do that, you can add an additional address by separating them with a semi colon:
server.urls=http://localhost:5000;http://{my_kestrel_ip}:5000
The hosting.ini was not working for us. I have to add this to the project.json file. I believe that the hosting.ini file is being deprecated after Beta8.
--server.urls http://0.0.0.0:5000
or I prefer the following which I believe is less confusing.
--server.urls http://*:5000
So you would end up with something like this in your project.json.
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000",
"ef": "EntityFramework.Commands"
},
Just did a quick test that seems to work. Create a hosting.json file beside your project.json file.
hosting.json:
{
"server.urls": "http://localhost:5000;http://192.168.1.4:5000"
}
project.json:
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --config hosting.json"
},
In a command prompt simply run dnx web
, output:
Hosting environment: Production
Now listening on: http://localhost:5000
Now listening on: http://192.168.1.4:5000
Application started. Press Ctrl+C to shut down.
You'll get a firwall prompt, accept it, and tadaaa!! You can access the site from the LAN and localhost.
来源:https://stackoverflow.com/questions/33975949/asp-net-5-kestrel-connect-within-lan