如何发布自定义网页的Hangfire信息中心

如何发布自定义网页的Hangfire信息中心

本文介绍了如何发布自定义网页的Hangfire信息中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Hangfire仅出于安全目的将其仪表板设置为本地.然后,如果要在自定义域中打开它,则必须为其设置授权.我遵循了配置授权指南,但是我不明白在app.UseCookieAuthentication(…)中必须写些什么.

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()
{

});

返回错误

该代码可能已被弃用,无法正常工作.关于此的所有主题都来自几年前,所以我不知道从那时起它们已经更新了什么.同时,与此同时,我希望对所有人开放,因此我真的不需要为任何角色设置身份验证.

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.

推荐答案

正如您在评论注释中所要求的那样,如果要在不让应用程序在本地主机上运行的情况下设置对仪表板的公共访问,则需要添加自定义DashboardAuthorizationFilter将始终返回true(授权任何人获得访问权限).

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

这篇关于如何发布自定义网页的Hangfire信息中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:22