Skip to content

授权问题

yuzd edited this page Jan 16, 2022 · 2 revisions

如果你希望你的hangfire dashbord设置授权才能访问,需要做以下事情

目前只支持basicauth授权,需要:Install-Package Hangfire.Dashboard.BasicAuthorization

还需要设置 IgnoreAntiforgeryToken = true,更详细的请查看 QuickStart

app.UseHangfireDashboard(hangfireStartUpPath, new DashboardOptions
            {
                AppPath = "#",
                IgnoreAntiforgeryToken = true,//这里一定要写true 不然用client库写代码添加webjob会出错
                DisplayStorageConnectionString = false,
                IsReadOnlyFunc = Context => false,
                Authorization = new[] { new BasicAuthAuthorizationFilter(new BasicAuthAuthorizationFilterOptions
                {
                    RequireSsl = false,
                    SslRedirect = false,
                    LoginCaseSensitive = true,
                    Users = new []
                    {
                        new BasicAuthAuthorizationUser
                        {
                            Login = "admin",
                            PasswordClear =  "test"
                        }
                    }

                }) }
            });