'HangFire dashboard not displaying in PROD

I am using HangFire to schedule jobs but when I deployed to PROD, the website/hangfire url is not working. I am getting The system cannot find the file specified error.

On localhost, I am able to open the URL.

I followed this URL: http://docs.hangfire.io/en/latest/quick-start.html

Anyone know what I am missing.

Thanks



Solution 1:[1]

Hangfire Dashboard exposes sensitive information about your background jobs, including method names and serialized arguments as well as gives you an opportunity to manage them by performing different actions – retry, delete, trigger, etc. So it is really important to restrict access to the Dashboard.

To make it secure by default, only local requests are allowed, however you can change this by passing your own implementations of the IAuthorizationFilter interface, whose Authorize method is used to allow or prohibit a request. The first step is to provide your own implementation.

http://docs.hangfire.io/en/latest/configuration/using-dashboard.html#configuring-authorization

Solution 2:[2]

As Hangfire dashboard exposes sensitive information about your job which includes method names and serialized arguments. Also user can perform different actions like retry, trigger, delete etc. So it is very important to authenticate access to Dashboard.

By default Hangfire allows access to Dashboard pages only for local requests. In order to give appropriate rights for production or testing or UAT users, add your own implementation of authorization using the IDashboardAuthorizationFilter interface for the hangfire dashboard.

http://docs.hangfire.io/en/latest/configuration/configuring-authorization.html

See my sample code below

public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter
{
    private readonly string[] _roles;

    public HangfireAuthorizationFilter(params string[] roles)
    {
        _roles = roles;
    }

    public bool Authorize(DashboardContext context)
    {
        var httpContext = ((AspNetCoreDashboardContext)context).HttpContext;

        //Your authorization logic goes here.

        return true; //I'am returning true for simplicity
    }
}

Asp.net core startup class changes in Configure(IApplicationBuilder app, IHostingEnvironment env) method

Configure(IApplicationBuilder app, IHostingEnvironment env){
      ......
        app.UseHangfireServer();
        app.UseHangfireDashboard("/hangfire", new DashboardOptions
        {               
            DashboardTitle = "Sample Jobs",
            Authorization = new[]
            {
                new  HangfireAuthorizationFilter("admin")
            }
        });
      ......
      }

Solution 3:[3]

Maybe a late answer but might be usefull.

In my case, I had this code :

  public class Startup
  {
    public void Configuration(IAppBuilder app)
    {
      #if !DEBUG
          app.UseHangfireDashboard("/hangfire", new DashboardOptions
          {
            Authorization = new[] { new HangfireAuthFilter() }
          });
       #endif
    }
   }
 }

It wasn't working on prod. I realized that when I copy the application dll from the bin folder, it takes the debug configuration and doesn't start the hangfire. When I publish the application via visual studio and than copy the DLL from the bin folder of published folder, it works correctly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mpora
Solution 2 Bibin Gangadharan
Solution 3 Coskun Ozogul