/// <summary> /// Retrieves full url path to the exact application path. ex: http://www.somesite.com/webapplication /// </summary> /// <returns>url</returns> public static string FullyQualifiedApplicationPath() { //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}{3}", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port == 80 ? string.Empty : ":" + context.Request.Url.Port.ToString(), context.Request.ApplicationPath); } 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