I don't think there is a sure way to do this:
- IIS can map a number of ips, hostnames and ports to a web application
- Each request can be bound to a different one
You probably need to do one of these things:
- change your code so the binding is only needed when you have a request and not at application start
- if you know the correct value before hand , you can set it by storing it via a configuration key