There is Prefixes
field in HttpListener
. You can add some string like "http://+:8080/" and your application just process all queries to 8080 port.
I have HttpSelfHostServer
it can use only valid Uri string like input to it HttpSelfHostConfiguration
class. I want to get same behaviour in my HttpSelfHostServer
like in HttpListener
with prefixes like:
http://*:8080/
And so on...
...
var configuration = new HttpSelfHostConfiguration(prefix)
var server = new HttpSelfHostServer(configuration);
...
localhost gets rewritten to +
in this case, so localhost:8080
, 0.0.0.0:8080
, 127.0.0.1:8080
should all work in the case you want to listen on all interfaces.
In the case where you don't want this automatic re-writing to happen, The second argument for HttpSelfHostConfiguration
takes a HostNameComparisonMode
which can be set to Exact
.