C#: Get Web Base URL

Get Web Base URL using .NET/C#. This gets the base URL of the web site you are running on.

C# Code Snippets

C#: Get Web Base URL

This gets the base URL of the web site you are running on.

public static string GetWebRootURL()
{
  // this is the base url or web address of the system (and ends with /)

  string baseUrl = System.Web.HttpContext.Current.Request.Url.Scheme + "://"
    + System.Web.HttpContext.Current.Request.Url.Authority
    + System.Web.HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + '/';

  return baseUrl;
}