I would like to get the fully qualified root URI of an application without a context. I like the answer below, but if context is null then it will crash. Is there a better way to do this? Is there really nothing in the .NET API for this still (even 4.5)?
Share
If you have multiple bindings configured in IIS, how would it know, since there is no single fully qualified root URI?
I’m right now adding it to the web.config since I have an EMail generator that needs to know the URL, but technically I have at least three different valid URLs.
HttpContext does tell you how the current request is being called. You could use IIS Management APIs to get Site Bindings though.