ASP.NET 5 Kestrel在LAN内连接
我想从同一网络中的另一台PC上连接到我的Kestrel服务器,其中包含ASP.NET 5应用程序。 可能吗? 我可以从cmd ping我的电脑,但是当我尝试从网络浏览器连接时,我得到’连接超时’(我输入:“http:// {my_kestrel_ip}:5000 /”)。
在项目文件夹中,您应该有一个名为hosting.ini
的文件。 默认情况下,在该文件中,您应该具有以下内容:
server=Kestrel server.urls=http://localhost:5000
您需要让HTTP服务器侦听您的公共IP地址以及localhost。 为此,您可以通过用冒号分隔来添加其他地址:
server.urls=http://localhost:5000;http://{my_kestrel_ip}:5000
hosting.ini不适合我们。 我必须将它添加到project.json文件中。 我相信在Beta8之后,hosting.ini文件已被弃用。
--server.urls http://0.0.0.0:5000
或者我更喜欢以下我认为不那么令人困惑的东西。
--server.urls http://*:5000
所以你最终会在project.json中得到类似的东西。
"commands": { "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://0.0.0.0:5000", "ef": "EntityFramework.Commands" },
刚做了一个似乎有用的快速测试。 在project.json文件旁边创建一个hosting.json文件。
hosting.json:
{ "server.urls": "http://localhost:5000;http://192.168.1.4:5000" }
project.json:
"commands": { "web": "Microsoft.AspNet.Server.Kestrel --config hosting.json" },
在命令提示符下运行dnx web
,输出:
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.
你会得到一个firwall提示,接受它,并且tadaaa !! 您可以从LAN和localhost访问该站点。