It may appear to be going overboard but this is the helper routine I use. I haven't run into any troubles with it yet.
public class UrlHelper
{
public static string ApplicationBaseUrl()
{
string port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
if (port == null || port == "80" || port == "443")
port = "";
else
port = ":" + port;
string protocol = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
if (protocol == null || protocol == "0")
protocol = "http://";
else
protocol = "https://";
return protocol + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port +
HttpContext.Current.Request.ApplicationPath;
}
}