Dashboard URL issues when deployed below site root

There seem to be a few problems with the dashboard with regards to URLs when the hosting application is deployed in a virtual folder/subdirectory (http://domain.com/app) instead of the site root (http://domain.com).

  1. When the server is configured to use a different dashboard path than the default (/hangfire) using the app.UseDashboardPath() method, the dashboard cannot be reached. When you navigate to the configured dashboard URL, a 404 error is returned by the server. If the dashboard path is left as default, it can be reached as expected.

  2. When a user clicks the ā€˜Return to siteā€™ link in the navigation bar within the dashboard, it navigates the user to the site root (http://domain.com).

If there is something else I need to consider to correctly configure the dashboard and return links to be reachable from a path other than default inside a virtual folder under site root, please let me know. Thank you.

The relevant snippet of my OWIN startup code follows:

app.UseHangfire(config =>
{
    config.UseSqlServerStorage("DbContext");
    config.UseNinjectActivator(new Bootstrapper().Kernel);

    // set path to Hangfire Dashboard
    config.UseDashboardPath(VirtualPathUtility.ToAbsolute("~/BackgroundJobs"));          

    // only users with Administrator role are authorized to access the Hangfire Dashboard
    config.UseAuthorizationFilters(new AuthorizationFilter { Roles = "Administrator" });

    // activate Hangfire background job server (for executing jobs)
    config.UseServer();
});

Scheduled this feature to 1.4.0

Great - that should resolve my issue #2. Do you have any input on my issue #1, or is this an issue also being addressed in 1.4.0?

Have you tried to use UseDashboardPath("/BackgroundJobs") instead of VirtualPathUtility? Dashboard is plugged in as an OWIN middleware, and VirtualPathUtility can be unnecessary for that.

Indeed, configuring it using the path ā€œ/BackgroundJobsā€ worked fine. Upon a closer look, I found that the problem was that I was trying to build a hyperlink in my UI to the dashboard using the same string value the dashboard path was configured with. In cases where the app is deployed to the site root, this works fine - but breaks down when deployed in a folder below the root.

I resolved my issue by configuring my dashboard path as ā€œ/BackgroundJobsā€ and building my hyperlink using that string with a ā€œ~ā€ appended so that it can be reached regardless of where it is deployed.

Thanks for the assistance, and I look forward to 1.4.0. Great product!

1 Like

This is the exact problem I am having too. However I am not using OWIN but instead I am using the HangfireBootStrapper class from http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html

How can I map the path to a sub application if I am not using OWIN?

Hi gdereese,

Could you please share me for How to change hyperlink to using that string with a ā€œ~ā€ appended that you fixed on your application?

Many Many Thanks.
Nantanart.

1 Like

Iā€™m also at a loss here. My web app has the URL https://ServerAddress/MyWebApp, so when I click ā€œBack to siteā€ from the Dashboard, it returns https://ServerAddress only.
Iā€™m using .NET 5. Can I get info on how to correctly configure the Back to site button?

Hi

Iā€™ve updated to .net 6 recently so my app is running in the defaults i.e. Kestrel and Iā€™ve just noticeback to site is having the same issue where it seems to strip the path. So my ā€œsiteā€ is a separate app entirely running at https://my.site.com/app and hangfire runs on https://my.site.com/app/scheduler, but the back to site link is being rendered as https://my.site.com and so doesnā€™t work.

Does anyone know of a workaround or fix to this?

Many thanks

Andy

Andy,

I probably wonā€™t be able to help, but I can do some testing locally and see if I can find anything to help. I do have a .NET 6.0 web app set up running Hangfire, but itā€™s running at the root level. Can you let me know how you have configured your .NET 6 app to run as a sub-application? Are you only doing this on the server (in IIS) when you publish/deploy the app, or do you also have it set up to run as a sub-app in Visual Studio?

Andy,

I did a bit of testing with a .NET 6.0 ASP.NET site (using the ā€œminimalā€ style), and I think the following should work.

In Program.cs (just after ā€œapp.UseRouting();ā€ and ā€œapp.UseAuthorization();ā€), add the following:

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHangfireDashboard(new DashboardOptions { AppPath = ā€œ/myhangfireappā€ }, null);
});

Set ā€œ/myhangfireappā€ to your desired app name/path (and it does need the leading ā€œ/ā€). This sets the ā€œBack to Siteā€ link to this path.

You can use additional options for the MapHangfireDashboard method, like this:

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHangfireDashboard(ā€œ/dashboard-tasksā€, new DashboardOptions { DashboardTitle = ā€œMy App Dashā€, AppPath = ā€œ/myhangfireappā€ }, null);
});

Note that there is also a ā€œPrefixPathā€ option in the DashboardOptions, but I couldnā€™t get that to work as expected when I tried it.

The AppPath option is also described in the documentation here:
https://docs.hangfire.io/en/latest/configuration/using-dashboard.html#change-back-to-site-link

Thanks Philip

Iā€™ll give that a go

I figured it out, I already had the prefixed ā€œ/ā€ however the new MapDashboard and UseDashboard were double registering the dashboard and consequently overwriting the configuration. I removed UseDashboard in favour of MapDashboard and all is well.