From 23a56fe43b123ca3c4f276e898b2f93dee963f39 Mon Sep 17 00:00:00 2001 From: JamesPasta Date: Wed, 6 May 2026 14:23:14 -0700 Subject: [PATCH] feature/AB#32874-FixBaseUrl Co-authored-by: Copilot --- .../EmailNotificationService.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Application/EmailNotificaions/EmailNotificationService.cs b/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Application/EmailNotificaions/EmailNotificationService.cs index 5471937cb..0a31ff2c4 100644 --- a/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Application/EmailNotificaions/EmailNotificationService.cs +++ b/applications/Unity.GrantManager/modules/Unity.Notifications/src/Unity.Notifications.Application/EmailNotificaions/EmailNotificationService.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Extensions.Logging; using System; @@ -16,7 +17,6 @@ using Volo.Abp.DependencyInjection; using Volo.Abp.Features; using Volo.Abp.SettingManagement; -using Volo.Abp.UI.Navigation.Urls; using Volo.Abp.Users; namespace Unity.Notifications.EmailNotifications; @@ -29,7 +29,7 @@ public class EmailNotificationService( IExternalUserLookupServiceProvider externalUserLookupServiceProvider, ISettingManager settingManager, IFeatureChecker featureChecker, - IAppUrlProvider appUrlProvider) : ApplicationService, IEmailNotificationService + IHttpContextAccessor httpContextAccessor) : ApplicationService, IEmailNotificationService { public async Task InitializeDraftAsync(Guid applicationId) @@ -72,10 +72,24 @@ protected virtual async Task NotifyTeamsChannel(string chesEmailError) await notificationAppService.PostToTeamsAsync(activityTitle, activitySubtitle); } - public async Task GetBaseUrlAsync() + public Task GetBaseUrlAsync() { - var appUrl = await appUrlProvider.GetUrlAsync(appName: "MVC"); - return appUrl; + var httpContext = httpContextAccessor.HttpContext + ?? throw new InvalidOperationException("No active HTTP context available to resolve base URL."); + + var request = httpContext.Request; + + var host = request.Headers["X-Forwarded-Host"].FirstOrDefault() + ?? request.Host.Value; + + var scheme = request.Headers["X-Forwarded-Proto"].FirstOrDefault() + ?? request.Scheme; + + var pathBase = request.Headers["X-Forwarded-Prefix"].FirstOrDefault() + ?? request.PathBase.Value + ?? string.Empty; + + return Task.FromResult($"{scheme}://{host}{pathBase}".TrimEnd('/')); } public async Task SendCommentNotification(EmailCommentDto input)