I am using this code in my hub currently, I am sure there is a better way to do this, but it works.
Note. If you want the full URL, make sure you set the domain correctly (example.com).
protected virtual UrlHelper Url { get { var httpContext = HttpContext.Current; if (httpContext == null) { var request = new HttpRequest("/", "http://example.com", ""); var response = new HttpResponse(new StringWriter()); httpContext = new HttpContext(request, response); } var httpContextBase = new HttpContextWrapper(httpContext); var routeData = new RouteData(); var requestContext = new RequestContext(httpContextBase, routeData); return new UrlHelper(requestContext); } }
source share