Accessing HangFire over Gateway is failing. Not able to load CSS and JS

  1. I’m hosting HangFire on Application server under - https://domainurl:portnumber/
    And HangFire dashboard URL would be: https://domainurl:portnumber/backgroundqueues
  2. Application server is accessed over Gateway: https://gatewayurl/bl
    So, final HangFire dashboard URL would be: https://gatewayurl/bl/backgroundqueues

I’m configuring HangFire dashboard in Owin startup using below code:
app.UseHangfireDashboard("/backgroundqueues", dashboardOptions);

When I’m trying to access HangFire dashboard it is not able to load the CSS and JS files, as it is trying to locate them at https://gatewayurl/backgroundqueues instead of https://gatewayurl/bl/backgroundqueues
Also, when I’m accessing other links on home page.
For ex., Jobs, it is not loading correct url: It is loading https://gatewayurl/backgroundqueues/jobs/enqueued instead of https://gatewayurl/bl/backgroundqueues/jobs/enqueued

One possible solution is to make the configuration
app.UseHangfireDashboard("./backgroundqueues", dashboardOptions);
But, currently it is invalid configuration

OR

When the page is rendered all the relative paths have either “./” or nothing instead of “/”.

HangFire.Core.dll version: 1.6.15.0
Application .NET version: 4.6.1

Please help me in resolving the issue.
Thanks in advance.

Below solution worked for me!!!

Your gateway is probably setting X-Forwarded-PathBase header when forwarding requests to the backend server (or at least could be configured to do so).

So you may set up an OWIN middleware to rewrite Request.PathBase value with a value from header if it is present. This should make the links to be correctly resolved.

Something like:

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