2024-04-05 04:26:57 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace ActivityPub.Utils;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <see cref="IUrlHelper"/> extension methods.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class UrlHelperExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a fully qualified URL to an action method by using the specified action name, controller name and
|
|
|
|
|
/// route values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">The URL helper.</param>
|
|
|
|
|
/// <param name="actionName">The name of the action method.</param>
|
|
|
|
|
/// <param name="controllerName">The name of the controller.</param>
|
|
|
|
|
/// <param name="routeValues">The route values.</param>
|
|
|
|
|
/// <returns>The absolute URL.</returns>
|
2024-05-02 04:54:14 +00:00
|
|
|
|
public static string? AbsoluteAction(
|
2024-04-05 04:26:57 +00:00
|
|
|
|
this IUrlHelper url,
|
|
|
|
|
string actionName,
|
|
|
|
|
string controllerName,
|
2024-05-02 04:54:14 +00:00
|
|
|
|
object? routeValues = null)
|
2024-04-05 04:26:57 +00:00
|
|
|
|
{
|
|
|
|
|
return url.Action(actionName, controllerName, routeValues, url.ActionContext.HttpContext.Request.Scheme);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a fully qualified URL to the specified content by using the specified content path. Converts a
|
|
|
|
|
/// virtual (relative) path to an application absolute path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">The URL helper.</param>
|
|
|
|
|
/// <param name="contentPath">The content path.</param>
|
|
|
|
|
/// <returns>The absolute URL.</returns>
|
|
|
|
|
public static string AbsoluteContent(
|
|
|
|
|
this IUrlHelper url,
|
|
|
|
|
string contentPath)
|
|
|
|
|
{
|
|
|
|
|
HttpRequest request = url.ActionContext.HttpContext.Request;
|
|
|
|
|
return new Uri(new Uri(request.Scheme + "://" + request.Host.Value), url.Content(contentPath)).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generates a fully qualified URL to the specified route by using the route name and route values.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="url">The URL helper.</param>
|
|
|
|
|
/// <param name="routeName">Name of the route.</param>
|
|
|
|
|
/// <param name="routeValues">The route values.</param>
|
|
|
|
|
/// <returns>The absolute URL.</returns>
|
2024-05-02 04:54:14 +00:00
|
|
|
|
public static string? AbsoluteRouteUrl(
|
2024-04-05 04:26:57 +00:00
|
|
|
|
this IUrlHelper url,
|
|
|
|
|
string routeName,
|
2024-05-02 04:54:14 +00:00
|
|
|
|
object? routeValues = null)
|
2024-04-05 04:26:57 +00:00
|
|
|
|
{
|
|
|
|
|
return url.RouteUrl(routeName, routeValues, url.ActionContext.HttpContext.Request.Scheme);
|
|
|
|
|
}
|
|
|
|
|
}
|