Tôi đã tải về nu-get gói Hangfire.Dashboard.Authorization
Hangfire Dashboard Authorization Config Không làm việc
Tôi đang cố gắng cấu hình OWIN dựa uỷ quyền theo các tài liệu như sau nhưng tôi nhận được lỗi IntelliSense DashboardOptions.AuthorizationFilters is obsolete please use Authorization property instead
Tôi cũng nhận được lỗi IntelliSense The type or namespace AuthorizationFilter and ClaimsBasedAuthorizationFilterd not be found
using Hangfire.Dashboard;
using Hangfire.SqlServer;
using Owin;
using System;
namespace MyApp
{
public class Hangfire
{
public static void ConfigureHangfire(IAppBuilder app)
{
GlobalConfiguration.Configuration
.UseSqlServerStorage(
"ApplicationDbContext",
new SqlServerStorageOptions
{ QueuePollInterval = TimeSpan.FromSeconds(1) });
var options = new DashboardOptions
{
AuthorizationFilters = new[]
{
new AuthorizationFilter { Users = "admin, superuser", Roles = "advanced" },
new ClaimsBasedAuthorizationFilter("name", "value")
}
};
app.UseHangfireDashboard("/hangfire", options);
app.UseHangfireServer();
}
}
}
* CẬP NHẬT *
Vì công phu NuGet gói doesnt trên, chúng tôi đã cố gắng để tạo bộ lọc tùy chỉnh của riêng tôi:
public class HangfireAuthorizationFilter : IAuthorizationFilter
{
public bool Authorize(IDictionary<string, object> owinEnvironment)
{
// In case you need an OWIN context, use the next line,
// `OwinContext` class is the part of the `Microsoft.Owin` package.
var context = new OwinContext(owinEnvironment);
// Allow all authenticated users to see the Dashboard (potentially dangerous).
return context.Authentication.User.Identity.IsAuthenticated;
}
}
Làm thế nào để hạn chế để chỉ vai trò quản lý tức là cú pháp là gì?
Phiên bản nào của HF bạn đang sử dụng? Ngoài ra hãy hiển thị các không gian tên bạn đã nhập trong lớp. – Yogi
@Yogi Hangfire core là 1.6.1 và Hangfire.Dashborad.Authorization là 2.1.0. Tôi đã cập nhật bài đăng để hiển thị không gian tên. – adam78