79782254

Date: 2025-10-04 01:07:26
Score: 1.5
Natty:
Report link

First off, all credit goes to this guy:

https://andrewlock.net/using-pathbase-with-dotnet-6-webapplicationbuilder/

In Program.cs:

// Filter PathBase when hosted on platforms using relative path like Github Pages
// so that pages route the same way. This version ensures app.UsePathBase("/MyApp") doesn't get clobbered by other middleware.
builder.Services.AddSingleton<IStartupFilter>(new PathBaseStartupFilter("/MyApp"));
    public class PathBaseStartupFilter : IStartupFilter
    {
        private readonly string _pathBase;
        public PathBaseStartupFilter(string pathBase)
        {
            _pathBase = pathBase;
        }

        public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
        {
            return app =>
            {
                app.UsePathBase(_pathBase);
                next(app);
            };
        }
    }
Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Hoppy