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.
40 lines
1.5 KiB
40 lines
1.5 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Globalization;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class UrlHelperExtensions
|
|
{
|
|
public static string GetFullUrl(this IUrlHelper url, string visualPath)
|
|
{
|
|
if (url is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(url));
|
|
}
|
|
if (string.IsNullOrEmpty(visualPath))
|
|
{
|
|
return visualPath;
|
|
}
|
|
var request = url.ActionContext.HttpContext.Request;
|
|
if (visualPath.StartsWith("~", StringComparison.Ordinal))
|
|
{
|
|
return string.Format(CultureInfo.InvariantCulture, "{0}://{1}{2}", request.Scheme, request.Host, url.Content(visualPath));
|
|
}
|
|
else if (visualPath.StartsWith("/", StringComparison.Ordinal))
|
|
{
|
|
return string.Format(CultureInfo.InvariantCulture, "{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)
|
|
{
|
|
if (helper is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(helper));
|
|
}
|
|
return helper.Action(action, controller, values, scheme ?? helper.ActionContext.HttpContext.Request.Scheme, host);
|
|
}
|
|
}
|
|
} |