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)?
Asked
Active
Viewed 725 times
2 Answers
2
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.

Michael Stum
- 177,530
- 117
- 400
- 535
1
You need something to ask for the url. Having a context suggests you're in the app & can ask it.
If you're not in the app then you need to get it so you can ask it. The IIS api might be able to help you there.

Simon Halsey
- 5,459
- 1
- 21
- 32