4

Is it possible to host an OWIN web app (via WebApp.Start() or some other method) on a random port. I've looked at solutions like this (1) which use TcpListener to find a random port, or progressive scanning techniques like this (2), but it would be great if you could just do something like WebApp.Start("http://localhost:0") and be able to inspect the actual port binding.

To clarify: my issue with (1) is that the port is bound, then released, then rebound by the WebApp.Start method, and the second binding may fail inbetween (i.e. race condition). My issue with (2) is the potential inefficiency (although I have nothing to base this gut feeling on)

Community
  • 1
  • 1
flipchart
  • 6,548
  • 4
  • 28
  • 53
  • #2 is likely going to take some amount of time on the order of milliseconds. Do you really restart this app so often that performance here is an issue? If you do, you're doing something wrong. – Dark Falcon Sep 15 '14 at 16:09
  • so your question is how to host an OWIN web app on a random port or how to detect if there is a running service on a given port? :-) – Gianluca Ghettini Jul 15 '15 at 15:42

0 Answers0