You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Extensions/UrlHelperExtensions.cs

30 lines
1.1 KiB

using Microsoft.AspNetCore.Mvc;
namespace Infrastructure.Extensions
{
public static class UrlHelperExtensions
{
public static string GetFullUrl(this IUrlHelper url, string visualPath)
{
if (string.IsNullOrEmpty(visualPath))
{
return visualPath;
}
var request = url.ActionContext.HttpContext.Request;
if (visualPath.StartsWith("~"))
{
return string.Format("{0}://{1}{2}", request.Scheme, request.Host, url.Content(visualPath));
}
else if (visualPath.StartsWith("/"))
{
return string.Format("{0}://{1}{2}", request.Scheme, request.Host, visualPath);
}
return visualPath;
}
public static string FullAction(this IUrlHelper helper, string action = null, string controller = null, object values = null, string scheme = null, string host = null)
{
return helper.Action(action, controller, values, scheme ?? helper.ActionContext.HttpContext.Request.Scheme, host);
}
}
}