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

陌路散爱 提交于 2020-04-18 12:35:40

问题


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.


回答1:


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
        });


来源:https://stackoverflow.com/questions/60702161/how-can-i-publish-hangfire-dashboard-for-a-custom-web-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!