How can I get the root domain URI in ASP.NET?
string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
The GetLeftPart method returns a string containing the leftmost portion of the URI string, ending with the portion specified by part.
The scheme and authority segments of the URI.
For anyone still wondering, a more complete answer is available at http://devio.wordpress.com/2009/10/19/get-absolut-url-of-asp-net-application/.
public string FullyQualifiedApplicationPath{ get { //Return variable declaration var appPath = string.Empty; //Getting the current context of HTTP request var context = HttpContext.Current; //Checking the current context content if (context != null) { //Formatting the fully qualified website url/name appPath = string.Format("{0}://{1}{2}{3}", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port == 80 ? string.Empty : ":" + context.Request.Url.Port, context.Request.ApplicationPath); } if (!appPath.EndsWith("/")) appPath += "/"; return appPath; }}
HttpContext.Current.Request.Url can get you all the info on the URL. And can break down the url into its fragments.