How can I consistently get the absolute, fully-qualified root or base url of the site regardless of whether the site is in a virtual directory and regardless of where my code is in the directory structure? I've tried every variable and function I can think of and haven't found a good way.
I want to be able to get the url of the current site, i.e. http://www.mysite.com or if it's a virtual directory, http://www.mysite.com/DNN/
Here's some of the things I've tried and the result. The only one that includes the whole piece that I want (http://localhost:4471/DNN441) is Request.URI.AbsoluteURI:
Request.PhysicalPath: C:\WebSites\DNN441\Default.aspx Request.ApplicationPath: /DNN441 Request.PhysicalApplicationPath: C:\WebSites\DNN441\ MapPath: C:\WebSites\DNN441\DesktopModules\Articles\Templates\Default.aspx RawURL: /DNN441/ModuleTesting/Articles/tabid/56/ctl/Details/mid/374/ItemID/1/Default.aspx Request.Url.AbsoluteUri: http://localhost:4471/DNN441/Default.aspx Request.Url.AbsolutePath: /DNN441/Default.aspx Request.Url.LocalPath: /DNN441/Default.aspx Request.Url.Host: localhost Request.Url.PathAndQuery: /DNN441/Default.aspx?TabId=56&ctl=Details&mid=374&ItemID=1