Skip to content

Instantly share code, notes, and snippets.

@druttka
Created January 25, 2012 22:14
Show Gist options
  • Save druttka/1679190 to your computer and use it in GitHub Desktop.
Save druttka/1679190 to your computer and use it in GitHub Desktop.
Absolute URL given HttpContext, action, and controller
// Assuming you have an HttpContext named httpContext
var urlHelper = new UrlHelper(httpContext.Request.RequestContext, RouteTable.Routes);
var url = urlHelper.Action("ActionName", "ControllerName");
// Or you can get really explicit and include the scheme and host
url = urlHelper.Action("ActionName", "ControllerName", null, httpContext.Request.Url.Scheme, httpContext.Request.Url.Host);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment