/// <summary>
/// Retrieves full url path of the host. ex: http://www.somesite.com/
/// </summary>
/// <returns>url</returns>
public static string FullyQualifiedHostWebAddress()
{
//Return variable declaration
string appPath = null;
//Getting the current context of HTTP request
HttpContext context = HttpContext.Current;
//Checking the current context content
if (context != null)
{
//Formatting the fully qualified website url/name
appPath = string.Format("{0}://{1}{2}", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port == 80 ? string.Empty : ":" + context.Request.Url.Port.ToString());
}
if (!appPath.EndsWith("/"))
{
appPath += "/";
}
return appPath;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter