asp.net5自托管的WebListener连接超时 [英] asp.net5 selfhosted WebListener connection timeout

查看:110
本文介绍了asp.net5自托管的WebListener连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用控制台应用程序中托管的asp.net5 Web项目.它在localhost上运行良好,但是当我尝试通过不同的机器(例如 http://192.168.1.5:5432 等)访问此网站时,我得到了 ERR_CONNECTION_TIMED_OUT .我正在尝试几种更改方式,例如将localhost更改为计算机名称,但它们均无效.

I am using asp.net5 web project hosted in console app. It works fine on localhost, but when i try to access this website form different machine like http://192.168.1.5:5432 etc., i get ERR_CONNECTION_TIMED_OUT. I was trying several arouches like chaning localhost to machine name but none of them works.

hosting.ini文件:

hosting.ini file:

server=Microsoft.AspNet.Server.WebListener
server.urls=http://localhost:5432

是否有针对此问题的任何解决方案,或仅在控制台应用程序中托管用于开发目的

Is there any solution for this problem, or hosting in console app is only made for development purposes

推荐答案

由于您已将侦听器绑定到本地主机,因此它将仅接受与本地主机之间的连接. localhost 在这里是特殊的,因为它将(至少对于Kestrel)始终绑定到localhost/loopback接口.除 localhost 之外的所有内容都绑定到所有网络接口.

Because you have bound your listener to localhost it will only accept connections to (and from) localhost. localhost is special here as it will (at least for Kestrel) always bind to localhost/loopback interface. Everything other than localhost binds to all network interfaces.

如果您希望所有IP都可以访问它并且与主机/域无关,则必须使用 http://0.0.0.0:5432 (或者使用 http://*:5432 ).如果您执行 http://www.example.com:5432 ,则所有IP都可以访问它,但前提是在浏览器中键入了主机名,因此 http://192.168.1.5:5432 仍然无法正常工作(目前无法测试最后一个,但是*通配符url仍然可以正常工作).

If you want it to be reachable by all IPs and be host/domain agnostic, you have to use http://0.0.0.0:5432 (or alternatively http://*:5432). If you do http://www.example.com:5432, then it will be reachable from all IPs but only if the host name was typed in the browser so http://192.168.1.5:5432 still won't work (unable to test the last one right now, but * wild card url should still work).

这样,您可以在同一台服务器上运行多个asp.net核心应用程序,但它们具有不同的主机/域.

This way you can run multiple asp.net core applications on the same server but but with different hosts/domains.

如果将两个应用程序绑定到不同的端点,则它们也可以在相同的域和相同的端口上运行.

You can also run two applications on the same domain and same port, if you bind them to different endpoints.

例如 http://www.example.com/App1 http://www.example.com/App2 ,使用相同的端口和相同的域,但是不同的端点和两个应用程序.

For example http://www.example.com/App1 and http://www.example.com/App2, use same port and same domain but different endpoints and two applications.

修改

Windows用户的附加信息.您可能需要添加一个例外来更改本地安全设置,以允许dnx绑定到此端口/主机(或以不鼓励使用的Admin身份运行),尤其是在使用主机端口号和低端端口号(分别为80和443)时).

Addition information for windows users. You may have to add an exception to the change the local security settings to allow dnx to bind to this port/host (or run it as Admin which would be discouraged), especially when using host and low-numbered ports (80 and 443 respectively).

netsh http add iplisten ipaddress=0.0.0.0:80
netsh http add urlacl url=http://+:80/ user=Example\Username

这将允许域"Example"中的用户"Username"的应用程序开始侦听端口80.

This will allow applications for the user "Username" in the domain "Example" to start listening on port 80.

这篇关于asp.net5自托管的WebListener连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆