Hangfire 仪表板链接指向错误的路线

Hangfire Dashboard links point to wrong routes

问题是,当应用程序部署到非根上下文时(即 http://root/someAppName/ 仪表板默认可在 http://root/someAppName/hangfire 访问)。 但是仪表板缺少任何 js 和 css,因为它们是从错误的位置下载的。 链接也会出现同样的问题(位置错误)。它们都指向 http://root/someLinkName 跳过上下文的 /someAppName 部分。 我正在使用 ASP.NET Core 2.2.

发现了类似的问题 here,但尚未解决,此外,也没有涉及 ASP.NET 核心。如何正确设置我的应用程序以缓解此问题?该应用程序无法部署到根上下文,需要保留在 /someAppName.

当带有 Hangfire 的 ASP.NET 核心应用程序部署在网关或负载平衡器后面时,这是一个已知问题。请参阅 this, this and this 以供参考。解决方法是配置网关(负载均衡器)将X-Forwarded-PathBase传递给应用程序,并在app.UseHangfireDashboard()之前添加以下中间件:

app.Use((context, next) =>
{
    var pathBase = context.Request.Headers["X-Forwarded-PathBase"];
    if (pathBase != null)
        context.Request.PathBase = new PathString(pathBase);
    return next();
});

app.UseHangfireDashboard();