diff --git a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs
new file mode 100644
index 0000000000..d307bc7e34
--- /dev/null
+++ b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Text;
+using System.Text.Json;
+using JetBrains.Annotations;
+using Swashbuckle.AspNetCore.SwaggerUI;
+using Volo.Abp;
+
+namespace Microsoft.Extensions.DependencyInjection;
+
+public static class AbpSwaggerUIOptionsExtensions
+{
+ ///
+ /// Sets the abp.appPath used by the Swagger UI scripts.
+ ///
+ /// The Swagger UI options.
+ /// The application base path.
+ public static void AbpAppPath([NotNull] this SwaggerUIOptions options, [NotNull] string appPath)
+ {
+ Check.NotNull(options, nameof(options));
+ Check.NotNull(appPath, nameof(appPath));
+
+ var normalizedAppPath = NormalizeAppPath(appPath);
+ options.HeadContent = BuildAppPathScript(normalizedAppPath, options.HeadContent ?? string.Empty);
+ }
+
+ private static string NormalizeAppPath(string appPath)
+ {
+ return string.IsNullOrWhiteSpace(appPath)
+ ? "/"
+ : appPath.Trim().EnsureStartsWith('/').EnsureEndsWith('/');
+ }
+
+ private static string BuildAppPathScript(string normalizedAppPath, string headContent)
+ {
+ var builder = new StringBuilder(headContent);
+ if (builder.Length > 0)
+ {
+ builder.AppendLine();
+ }
+
+ builder.AppendLine("");
+ return builder.ToString();
+ }
+}
diff --git a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js
index 11cbe56803..da996ea6f5 100644
--- a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js
+++ b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js
@@ -2,11 +2,7 @@ var abp = abp || {};
(function () {
/* Application paths *****************************************/
-
- //Current application root path (including virtual directory if exists).
- var baseElement = document.querySelector('base');
- var baseHref = baseElement ? baseElement.getAttribute('href') : null;
- abp.appPath = baseHref || abp.appPath || '/';
+ abp.appPath = abp.appPath || '/';
/* UTILS ***************************************************/
diff --git a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js
index db054056d1..e961f6bc2d 100644
--- a/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js
+++ b/framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js
@@ -11,7 +11,7 @@ var abp = abp || {};
var oidcSupportedScopes = configObject.oidcSupportedScopes || [];
var oidcDiscoveryEndpoint = configObject.oidcDiscoveryEndpoint || [];
var tenantPlaceHolders = ["{{tenantId}}", "{{tenantName}}", "{0}"]
- abp.appPath = configObject.baseUrl || abp.appPath;
+ abp.appPath = abp.appPath || "/";
var requestInterceptor = configObject.requestInterceptor;
var responseInterceptor = configObject.responseInterceptor;