One way to achieve this is a little trickster and contains warnings, but for using System.Web.Hosting.HostingEnvironment.SiteName
.
p>
So it will look like this:
string rURL = System.Web.Hosting.HostingEnvironment.SiteName;
And now for these caveats:
- This is the site name in IIS.
- This means that your site name may be a non-URI (for example, my excellent site).
- If you have multiple domains sharing the same site, they will be the same for each.
For my purposes - setting up logging on servers where I had several sites in IIS pointing to the same physical folder - the above solution was probably the simplest and easiest. I do not necessarily say this is the βrightβ answer, but it should be considered as an alternative.
source share