diff --git a/BTCPayServer.Abstractions/Extensions/HttpRequestExtensions.cs b/BTCPayServer.Abstractions/Extensions/HttpRequestExtensions.cs index c83c6bcfd..f0706daec 100644 --- a/BTCPayServer.Abstractions/Extensions/HttpRequestExtensions.cs +++ b/BTCPayServer.Abstractions/Extensions/HttpRequestExtensions.cs @@ -104,11 +104,6 @@ public static class HttpRequestExtensions return isRelative ? request.GetAbsoluteRoot() + redirectUrl : redirectUrl; } - public static Uri GetAbsoluteUriNoPathBase(this HttpRequest request, string relativeOrAbsolute) - { - return GetAbsoluteUriNoPathBase(request, new Uri(relativeOrAbsolute, UriKind.RelativeOrAbsolute)); - } - /// /// Will return an absolute URL. /// If `relativeOrAbsolute` is absolute, returns it. diff --git a/BTCPayServer.Tests/Mocks/UrlHelperMock.cs b/BTCPayServer.Tests/Mocks/UrlHelperMock.cs index 43182b943..d8286f787 100644 --- a/BTCPayServer.Tests/Mocks/UrlHelperMock.cs +++ b/BTCPayServer.Tests/Mocks/UrlHelperMock.cs @@ -15,7 +15,7 @@ namespace BTCPayServer.Tests.Mocks public string Action(UrlActionContext actionContext) { - return $"{_BaseUrl}mock"; + return $"/mock"; } public string Content(string contentPath) diff --git a/BTCPayServer/Controllers/GreenField/GreenfieldStoreOnChainWalletsController.cs b/BTCPayServer/Controllers/GreenField/GreenfieldStoreOnChainWalletsController.cs index f6c1e1ef8..474521e92 100644 --- a/BTCPayServer/Controllers/GreenField/GreenfieldStoreOnChainWalletsController.cs +++ b/BTCPayServer/Controllers/GreenField/GreenfieldStoreOnChainWalletsController.cs @@ -171,9 +171,8 @@ namespace BTCPayServer.Controllers.Greenfield var allowedPayjoin = derivationScheme.IsHotWallet && Store.GetStoreBlob().PayJoinEnabled; if (allowedPayjoin) { - var endpoint = Request.GetAbsoluteUriNoPathBase( - Url.Action(nameof(PayJoinEndpointController.Submit), "PayJoinEndpoint", - new { network.CryptoCode })).ToString(); + var endpoint = Url.ActionAbsolute(Request, nameof(PayJoinEndpointController.Submit), "PayJoinEndpoint", + new { network.CryptoCode }).ToString(); bip21.QueryParams.Add(PayjoinClient.BIP21EndpointKey, endpoint); } diff --git a/BTCPayServer/Controllers/UIServerController.cs b/BTCPayServer/Controllers/UIServerController.cs index 1a96fd54d..3e0f3f831 100644 --- a/BTCPayServer/Controllers/UIServerController.cs +++ b/BTCPayServer/Controllers/UIServerController.cs @@ -697,7 +697,7 @@ namespace BTCPayServer.Controllers var lnConfig = _LnConfigProvider.GetConfig(configKey); if (lnConfig != null) { - model.QRCodeLink = Request.GetAbsoluteUriNoPathBase(Url.Action(nameof(GetLNDConfig), new { configKey })).ToString(); + model.QRCodeLink = Url.ActionAbsolute(Request, nameof(GetLNDConfig), new { configKey }).ToString(); model.QRCode = $"config={model.QRCodeLink}"; } } diff --git a/BTCPayServer/Controllers/UIWalletsController.cs b/BTCPayServer/Controllers/UIWalletsController.cs index d9a7c3a2e..9c435f95f 100644 --- a/BTCPayServer/Controllers/UIWalletsController.cs +++ b/BTCPayServer/Controllers/UIWalletsController.cs @@ -404,9 +404,8 @@ namespace BTCPayServer.Controllers var bip21 = network.GenerateBIP21(address?.ToString(), null); if (allowedPayjoin) { - var endpoint = Request.GetAbsoluteUriNoPathBase( - Url.Action(nameof(PayJoinEndpointController.Submit), "PayJoinEndpoint", - new { cryptoCode = walletId.CryptoCode })).ToString(); + var endpoint = Url.ActionAbsolute(Request, nameof(PayJoinEndpointController.Submit), "PayJoinEndpoint", + new { cryptoCode = walletId.CryptoCode }).ToString(); bip21.QueryParams.Add(PayjoinClient.BIP21EndpointKey, endpoint); } diff --git a/BTCPayServer/Extensions/UrlHelperExtensions.cs b/BTCPayServer/Extensions/UrlHelperExtensions.cs index 8f22a50b1..b4d9a7cb6 100644 --- a/BTCPayServer/Extensions/UrlHelperExtensions.cs +++ b/BTCPayServer/Extensions/UrlHelperExtensions.cs @@ -1,6 +1,7 @@ using System; using BTCPayServer; +using BTCPayServer.Abstractions.Extensions; using BTCPayServer.Client.Models; using BTCPayServer.Controllers; using Microsoft.AspNetCore.Http; @@ -11,6 +12,12 @@ namespace Microsoft.AspNetCore.Mvc public static class UrlHelperExtensions { #nullable enable + public static Uri ActionAbsolute(this IUrlHelper helper, HttpRequest request, string? action, string? controller, object? values) + => request.GetAbsoluteUriNoPathBase(new Uri(helper.Action(action, controller, values) ?? "", UriKind.Relative)); + public static Uri ActionAbsolute(this IUrlHelper helper, HttpRequest request, string? action, string? controller) +=> request.GetAbsoluteUriNoPathBase(new Uri(helper.Action(action, controller) ?? "", UriKind.Relative)); + public static Uri ActionAbsolute(this IUrlHelper helper, HttpRequest request, string? action, object? values) +=> request.GetAbsoluteUriNoPathBase(new Uri(helper.Action(action, values) ?? "", UriKind.Relative)); public static string? EnsureLocal(this IUrlHelper helper, string? url, HttpRequest? httpRequest = null) { if (url is null || helper.IsLocalUrl(url)) diff --git a/BTCPayServer/Plugins/PointOfSale/Controllers/UIPointOfSaleController.cs b/BTCPayServer/Plugins/PointOfSale/Controllers/UIPointOfSaleController.cs index f45ac4edf..52e9beaf5 100644 --- a/BTCPayServer/Plugins/PointOfSale/Controllers/UIPointOfSaleController.cs +++ b/BTCPayServer/Plugins/PointOfSale/Controllers/UIPointOfSaleController.cs @@ -348,7 +348,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers RedirectAutomatically = settings.RedirectAutomatically, RedirectURL = !string.IsNullOrEmpty(redirectUrl) ? redirectUrl : !string.IsNullOrEmpty(settings.RedirectUrl) ? settings.RedirectUrl - : Request.GetAbsoluteUriNoPathBase(Url.Action(nameof(ViewPointOfSale), "UIPointOfSale", new { appId, viewType })).ToString(), + : Url.ActionAbsolute(Request, nameof(ViewPointOfSale), "UIPointOfSale", new { appId, viewType }).ToString(), PaymentMethods = paymentMethods?.Where(p => p.Value.Enabled).Select(p => p.Key).ToArray() }, AdditionalSearchTerms = new[] { AppService.GetAppSearchTerm(app) } @@ -534,7 +534,7 @@ namespace BTCPayServer.Plugins.PointOfSale.Controllers { var controller = nameof(UIPointOfSaleController).TrimEnd("Controller", StringComparison.InvariantCulture); var redirectUrl = - Request.GetAbsoluteUriNoPathBase(Url.Action(nameof(ViewPointOfSale), controller, new { appId, viewType })).ToString(); + Url.ActionAbsolute(Request, nameof(ViewPointOfSale), controller, new { appId, viewType }).ToString(); formParameters.Add("formResponse", FormDataService.GetValues(form).ToString()); return View("PostRedirect", new PostRedirectViewModel { diff --git a/BTCPayServer/Views/Shared/NFC/CheckoutEnd.cshtml b/BTCPayServer/Views/Shared/NFC/CheckoutEnd.cshtml index 642037e88..933f687e6 100644 --- a/BTCPayServer/Views/Shared/NFC/CheckoutEnd.cshtml +++ b/BTCPayServer/Views/Shared/NFC/CheckoutEnd.cshtml @@ -55,7 +55,7 @@ Vue.component("lnurl-withdraw-checkout", { }, data () { return { - url: @Safe.Json(Context.Request.GetAbsoluteUriNoPathBase(Url.Action("SubmitLNURLWithdrawForInvoice", "NFC")).ToString()), + url: @Safe.Json(Url.ActionAbsolute(Context.Request, "SubmitLNURLWithdrawForInvoice", "NFC").ToString()), amount: 0, submitting: false }