简体   繁体   English

C# Nancy.Hosting.Self 不响应来自网络的请求,只响应本地主机请求

[英]C# Nancy.Hosting.Self doesn't answer to requests from network, only to localhost request

I am trying to integrate nancy self hosting into my wpf project and when I start my program, I am able to connect to rest api from local browser, but cannot connect from another computer.我正在尝试将 nancy 自托管集成到我的 wpf 项目中,当我启动我的程序时,我能够从本地浏览器连接到 rest api,但无法从另一台计算机连接。

HostConfiguration hostConfigs = new HostConfiguration();
hostConfigs.UrlReservations.CreateAutomatically = true;

NancyHost host = new NancyHost(hostConfigs, new Uri("http://localhost:1234"));
host.Start();

Is there a way I can set Uri to wildcard, like in other built in web servers, 0.0.0.0 or + ?有没有办法可以将 Uri 设置为通配符,就像在其他内置网络服务器中一样, 0.0.0.0 或 + ?

EDIT Windows firewall is disabled!!编辑Windows 防火墙已禁用! I've also tried with different configurations of host, with http://10.10.10.149:1234 " as a host. I've tryed " http://+:1234 , this one doesn't build, it throws error.我还尝试了不同配置的主机,以http://10.10.10.149:1234 " 作为主机。我尝试了 " http://+:1234 ,这个没有构建,它抛出错误。

I've also completely removed hostConfigs and added ACL to the system by running some commands in powershell, like suggested in many articles:我还完全删除了 hostConfigs 并通过在 powershell 中运行一些命令将 ACL 添加到系统中,就像许多文章中建议的那样:

netsh http add urlacl url="http://+:12345/" user="Everyone"

Still, can only connect from local browser, not from another network location.尽管如此,只能从本地浏览器连接,不能从其他网络位置连接。 Whenever I try to connect to machine where program is running via rest api, I get 503 Service Unavailable.每当我尝试连接到通过 rest api 运行程序的机器时,我都会收到 503 Service Unavailable。

您需要将其更改为"http://+:1234"以绑定到所有网络接口。

SOLUTION解决方案

Although my firewall is disabled completely, it was the firewall that was causing problems.尽管我的防火墙已完全禁用,但导致问题的是防火墙。 I found solution in this article: C# HttpListener and Windows Firewall我在这篇文章中找到了解决方案: C# HttpListener and Windows Firewall

All I needed to do, was adding the rule for system program to firewall.我需要做的就是将系统程序的规则添加到防火墙。 If anyone comes to this problem, this solution worked for me.如果有人遇到这个问题,这个解决方案对我有用。 I can now access api from another LAN too, so I guess it would work from any remote IP.我现在也可以从另一个 LAN 访问 api,所以我想它可以从任何远程 IP 工作。

I have faced with a similar problem.我遇到了类似的问题。 I searched a lot of discussions and I had no answer.我搜索了很多讨论,但没有答案。 Then I found previous messages.然后我找到了以前的消息。 I worked for me.我为我工作。

It was a firewall issue.这是一个防火墙问题。 And the solution;和解决方案;

1- Go to firewall settings 2- Inbound firewall rules 3- Add a new rule 4- Connection point (TCP / UDP) 5- TCP 6- (Enter port numbers) 7- Allow connection 1- 进入防火墙设置 2- 入站防火墙规则 3- 添加新规则 4- 连接点(TCP / UDP) 5- TCP 6-(输入端口号) 7- 允许连接

I have shared my experience in case anyone need it.我已经分享了我的经验,以防有人需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM