Search code examples
hangfire

How can I publish Hangfire Dashboard for a custom web page?


I know that Hangfire set their dashboard to local only for security purposes. Then if I want to open it in a custom domain, I have to set the authorization for it. I have followed the Configuring Authorization guide but I don't understand what do I have to write inside app.UseCookieAuthentication(…).

app.UseCookieAuthentication(new CookieAuthenticationOptions()
{

});

It returns me an error of

Can't find namespace for CookieAuthenticationOptions

This code might be deprecated and does not work. All the topics about this are from a few years ago, so I don't know what they have updated from then on. Also in the mean time I want this to be open for all so I don't really need to set authentication for any role.


Solution

  • As you asked in comments comments, if you want to set up public access to your dashboard without app running at localhost, you need to add custom DashboardAuthorizationFilter which will always return true (authorize anybody to gain access).

    To do this create your filter as follows:

    using Hangfire.Dashboard;

    namespace your.app.namespace
    {
        public class PassThroughDashboardAuthorizationFilter : IDashboardAuthorizationFilter
        {
            /// <inheritdoc />
            public bool Authorize(DashboardContext context) => true;
        }
    }
    

    and then add it to your configuration:

            app.UseHangfireDashboard(options: new DashboardOptions
            {
                Authorization = new List<IDashboardAuthorizationFilter>(){ new PassThroughDashboardAuthorizationFilter() },
                IsReadOnlyFunc = context => false // according to your needs
            });