C# HttpListener and Windows Firewall
Asked Answered
W

1

6

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?

Winwaloe answered 25/7, 2013 at 16:8 Comment(4)
Are you adding the correct (debug/release) version to that configuration. Not sure if that makes a difference or not, but it may be location based.Briefless
I am using the Installed Release version (Installed with the Deployment Project Installer)Winwaloe
Have you tried to open the port directly?Galvin
Port 80 is open on my Router with DMZ enabled. I have an apache server that works just fine. I can get the HttpListener application to work ONLY if i create a firewall rule which allows any and all incoming connections through port 80.Winwaloe
E
18

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
Evoy answered 26/1, 2014 at 14:29 Comment(3)
Worked well for me. How did you figure out the name of the program should be "system"?Venison
I would love to know that too ;)Businesslike
@user1638737 - your edit looks useful, but could be considered to conflict with the author's intent. Why not make another answer?Tainataint

© 2022 - 2024 — McMap. All rights reserved.