I am trying to use this UrlHelper extension method:
public static string ToPublicUrl(this UrlHelper urlHelper, Uri relativeUri)
{
var httpContext = urlHelper.RequestContext.HttpContext;
var uriBuilder = new UriBuilder
{
Host = httpContext.Request.Url.Host,
Path = "/",
Port = 80,
Scheme = "http",
};
if (httpContext.Request.IsLocal)
{
uriBuilder.Port = httpContext.Request.Url.Port;
}
return new Uri(uriBuilder.Uri, relativeUri).AbsoluteUri;
}
This methd takes a relative Uri as a parameter. I am trying to call this method within a controller action and I cannot figure out how to get a relative Uri for the current Action
Can someone point me in the right direction?
You can get the relative path based on a specific action name using:
And you can get the someActionName, and someControllerName values for the current action using: