Created
January 25, 2012 22:14
-
-
Save druttka/1679190 to your computer and use it in GitHub Desktop.
Absolute URL given HttpContext, action, and controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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