ASP.NET 5 Kestrel connect within LAN

不打扰是莪最后的温柔 提交于 2019-11-29 11:35:42

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!