C# HttpListener and Windows Firewall

南楼画角 提交于 2019-12-06 05:24:59

问题


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. This is causing a big issue as the program needs to listen for remote connections, which are now being denied by the windows firewall.

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. 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?


回答1:


This is because HttpListener is built on top of http.sys which will listen on the port you specified on behalf of your program.

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:

  • 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


来源:https://stackoverflow.com/questions/17863294/c-sharp-httplistener-and-windows-firewall

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