0

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/

http://*:8080/

http://some.url:8080/

And so on...

...
var configuration = new HttpSelfHostConfiguration(prefix)
var server = new HttpSelfHostServer(configuration);
...
murzagurskiy
  • 1,273
  • 1
  • 20
  • 44

1 Answers1

2

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.

caesay
  • 16,932
  • 15
  • 95
  • 160
  • 1
    so, `http://+:8080/` is equal to `http://localhost:8080/`, `http://*:8080/` is equal to `http://0.0.0.0:8080/` and `http://some.url:8080/` is equal to `127.0.0.1:8080`. And for every of 3 cases what kind of `HostNameComparisonMode` I should use? I know: `Exact`, `StrongWildcard` and `WeakWildcard`, but don't know which one to use for which case? – murzagurskiy Mar 10 '17 at 05:17
  • When I try to use `http://+:8080/` I get an error `Invalid URI: The hostname could not be parsed` – Max Oct 11 '18 at 22:23
  • @Max: that's the point of this question and answer. you can't use `http://+:8080` because it's not a valid URI, but you can use the solution in my answer instead. – caesay Oct 12 '18 at 10:35