using Microsoft.AspNetCore.Mvc; namespace ActivityPub.Utils; /// /// extension methods. /// public static class UrlHelperExtensions { /// /// Generates a fully qualified URL to an action method by using the specified action name, controller name and /// route values. /// /// The URL helper. /// The name of the action method. /// The name of the controller. /// The route values. /// The absolute URL. public static string AbsoluteAction( this IUrlHelper url, string actionName, string controllerName, object routeValues = null) { return url.Action(actionName, controllerName, routeValues, url.ActionContext.HttpContext.Request.Scheme); } /// /// 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. /// /// The URL helper. /// The content path. /// The absolute URL. 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(); } /// /// Generates a fully qualified URL to the specified route by using the route name and route values. /// /// The URL helper. /// Name of the route. /// The route values. /// The absolute URL. public static string AbsoluteRouteUrl( this IUrlHelper url, string routeName, object routeValues = null) { return url.RouteUrl(routeName, routeValues, url.ActionContext.HttpContext.Request.Scheme); } }