Skip to content

Instantly share code, notes, and snippets.

@gerrod
Created November 21, 2012 04:50
Show Gist options
  • Save gerrod/4123084 to your computer and use it in GitHub Desktop.
Save gerrod/4123084 to your computer and use it in GitHub Desktop.
Get the URL base path
var uri = HttpContext.Request.Url;
var urlBase = Url.Content("~/");
var urlHost = String.Format("{0}://{1}{2}", uri.Scheme, uri.Host, uri.Port != 80
? String.Format(":{0}", uri.Port)
: String.Empty);
ViewBag.UrlBase = String.Format("{0}{1}", urlHost, urlBase);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment