簡體   English   中英

Hangfire 儀表板中的基本身份驗證注銷問題

[英]Basic Authentication logout issue in Hangfire Dashboard

我在ASP.NET Core 5應用程序中實現了Hangfire 對於身份驗證,我使用以下包:

https://www.nuget.org/packages/Hangfire.Dashboard.Basic.Authentication

在我運行應用程序並瀏覽到hangfire儀表板鏈接並插入正確的輸入值時,為hangfire儀表板實施身份驗證功能后,hangfire儀表板頁面正確顯示。

但是,我無法在hangfire 儀表板中處理身份驗證注銷功能。

我在下面為我的代碼提供示例:

應用設置.json

{
    "HangfireConfiguration":
    {
        "UserName": "admin",
        "Password": "admin123"
    }
}

啟動.cs:

using HangfireBasicAuthenticationFilter;

namespace Hangfire
{
    public IConfiguration _configuration { get; }

    public Startup(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        ......

        services.AddHangfire(config => config
            .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
            .UseSimpleAssemblyNameTypeSerializer()
            .UseDefaultTypeSerializer()                             
            .UseSqlServerStorage(_configuration.GetConnectionString("ApplicationDbContext"), new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                QueuePollInterval = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                UsePageLocksOnDequeue = true,
                DisableGlobalLocks = true
            }));
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ...)
    {
        var hangfireDashbaordOptions = new DashboardOptions
        {
            IgnoreAntiforgeryToken = true,
            AppPath = null,
            DashboardTitle = "Hangfire Dashboard",
            Authorization = new[]
            {
                new HangfireCustomBasicAuthenticationFilter
                {
                    User = _configuration.GetValue<string>("HangfireConfiguration:UserName"),
                    Pass = _configuration.GetValue<string>("HangfireConfiguration:Password")
                }
            }
        };

        app.UseHangfireDashboard("/hangfire", hangfireDashbaordOptions);

        var hangfireServerOptions = new BackgroundJobServerOptions
        {
            WorkerCount = Environment.ProcessorCount * 2,
            HeartbeatInterval = new TimeSpan(0, 1, 0),
            ServerCheckInterval = new TimeSpan(0, 1, 0),
            SchedulePollingInterval = new TimeSpan(0, 1, 0)
        };

        app.UseHangfireServer(hangfireServerOptions);

        ......
    }
}

如何從hangfire儀表板處理身份驗證注銷?

O seguinte deve funcionar

應用設置.json

{
    "HangfireConfiguration":
    {
        "UserName": "admin",
        "Password": "admin123",
        "AppPath": "https://logout:password@ENDERECO_DE_SUA_API/hangfire"
    }
}

啟動.cs:

...
var hangfireDashbaordOptions = new DashboardOptions
        {
            IgnoreAntiforgeryToken = true,
            AppPath = _configuration.GetValue<string>("HangfireConfiguration:AppPath"),
            DashboardTitle = "Hangfire Dashboard",
            Authorization = new[]
            {
                new HangfireCustomBasicAuthenticationFilter
                {
                    User = _configuration.GetValue<string>("HangfireConfiguration:UserName"),
                    Pass = _configuration.GetValue<string>("HangfireConfiguration:Password")
                }
            }
        };
...

Desta forma quando o usuário clicar em voltar no painel ele será desconectado e precisará fornecer novamente as credenciais。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM