简体   繁体   English

C#HttpListener和Windows防火墙

[英]C# HttpListener and Windows Firewall

One of the programs i am working on has a built in webserver, meant to only handle very specific requests (static). 我正在研究的其中一个程序具有内置的网络服务器,该服务器只能处理非常具体的请求(静态)。 Unlike a TcpListener, when the HttpListener is started, The user is NOT prompted to allow which networks the program is allowed to listen on. 与TcpListener不同,当启动HttpListener时,不会提示用户允许程序允许在哪些网络上侦听。 This is causing a big issue as the program needs to listen for remote connections, which are now being denied by the windows firewall. 这引起了一个大问题,因为该程序需要侦听远程连接,而Windows防火墙现在拒绝了这些连接。

If i make a new rule in the windows firewall, and select my program under "Programs and Services", windows will still deny all remote connections... but if I select "All programs that meet the specified conditions", then it works just fine. 如果我在Windows防火墙中制定了一个新规则,并在“程序和服务”下选择了我的程序,则Windows仍将拒绝所有远程连接...但是,如果我选择“所有符合指定条件的程序”,则它只能正常工作精细。 My question is why? 我的问题是为什么? Why does the firewall deny my application when its specifically selected? 为什么防火墙在明确选择我的应用程序后会拒绝它? And how come the user doesnt get prompted with the Firewall Security screen like with other Listeners? 以及为什么用户不会像其他侦听器一样在“防火墙安全性”屏幕上得到提示?

This is because HttpListener is built on top of http.sys which will listen on the port you specified on behalf of your program. 这是因为HttpListener构建在http.sys之上,它将在您代表程序指定的端口上进行侦听。

I haven't found a way to allow only a single program using HttpListener through the Windows Firewall, but you might want to limit your inbound rule to system components only by: 我还没有找到一种仅允许通过Windows防火墙使用HttpListener的程序的方法,但是您可能希望通过以下方式将入站规则限制为系统组件:

  • Entering typing system in the field "This program" in the tab "Program and services" 在“程序和服务”选项卡的“此程序”字段中输入键入系统
  • Selecting protocol type TCP in the tab "Protocols and Ports" together with the port you will be listening on 在“协议和端口”选项卡中选择协议类型TCP以及要监听的端口

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

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