Skip to content

Commit 44f06bd

Browse files
committed
Refined PathBase handling to only set it when the absolute path is not "/". This consolidates base URL logic and preserves any existing RequestUrlPrefix.
1 parent 337350f commit 44f06bd

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/OrchardCore/OrchardCore.Abstractions/BackgroundTasks/HttpContextExtensions.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/OrchardCore/OrchardCore/Modules/ModularBackgroundService.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ await shellScope.UsingAsync(async scope =>
166166
try
167167
{
168168
// Use the base url, if defined, to override the 'Scheme', 'Host' and 'PathBase'.
169-
_httpContextAccessor.HttpContext.SetBaseUrl((await siteService.GetSiteSettingsAsync()).BaseUrl);
169+
SetBaseUrl(_httpContextAccessor.HttpContext, (await siteService.GetSiteSettingsAsync()).BaseUrl);
170170
}
171171
catch (Exception ex) when (!ex.IsFatal())
172172
{
@@ -430,4 +430,25 @@ private void CleanSchedulers(string tenant, IEnumerable<IBackgroundTask> tasks)
430430
}
431431
}
432432
}
433+
434+
private static void SetBaseUrl(HttpContext context, string baseUrl)
435+
{
436+
if (Uri.TryCreate(baseUrl, UriKind.Absolute, out var uri))
437+
{
438+
context.Request.Scheme = uri.Scheme;
439+
context.Request.Host = new HostString(uri.Host, uri.Port);
440+
441+
// Set the PathBase only if it's not just "/". Otherwise, the original path base is kept, which may
442+
// contain the RequestUrlPrefix if any.
443+
if (!string.IsNullOrEmpty(uri.AbsolutePath) && uri.AbsolutePath != "/")
444+
{
445+
context.Request.PathBase = uri.AbsolutePath;
446+
}
447+
448+
if (!string.IsNullOrWhiteSpace(uri.Query))
449+
{
450+
context.Request.QueryString = new QueryString(uri.Query);
451+
}
452+
}
453+
}
433454
}

0 commit comments

Comments
 (0)