Hangfire Server and Dashboard in Two Different Web Applications

I have two web applications (ASP.NET MVC 5) and would like one of them to host the server and the other to host the dashboard. Think of Web App A as the client from which jobs are queued and Application B as the Admin where queued jobs can be monitored.

how can i go about this

Did you find the solution for your problem?

Yes I have found the solution

Could you please share the solution?

Basically, I had 2 ASP.MVC Web Applications,
1 for customers (CLIENT APPLICATION) and the other for admins (ADMIN APPLICATION).

I wanted to have the Hangfire dashboard accessible via the ADMIN APPLICATION and I wanted the CLIENT APPLICATION to be where Background Jobs are queued, the Hangfire Server is also resident on the CLIENT APPLICATION.

On the client and admin applications, install the following hangfire packages

  • Hangfire
  • Hangfire.Core
  • Hangfire.SqlServer
  • Hangfire.Dashboard.Authorization

These lines of code are in the OWIN Startup class of my client application,

    var options = new SqlServerStorageOptions { PrepareSchemaIfNecessary = true };
    GlobalConfiguration.Configuration.UseSqlServerStorage("[ConnectionStringName]", options);
    JobStorage.Current = new SqlServerStorage("[ConnectionStringName]", options);            

These lines of code are in the OWIN Startup class of my admin application,

            var options = new SqlServerStorageOptions{PrepareSchemaIfNecessary = true,};
            GlobalConfiguration.Configuration.UseSqlServerStorage(""[ConnectionStringName]"", options);
            JobStorage.Current = new SqlServerStorage(""[ConnectionStringName]"", options);
            app.UseHangfireDashboard("/admin/jobs", new DashboardOptions()
                Authorization = new[]
                { new HangFireAuthorizationFilter() }

I added an Authorization filter to restrict access to the dashboard to users in a particular role, or authenticated users.

1 Like