解決 ASP.NET Core Hangfire 未授權(401 Unauthorized)


相關文章:ASP.NET Core 使用 Hangfire 定時任務

ASP.NET Core Hangfire 在正式環境發布之后,如果訪問 http://10.1.2.31:5000/hangfire/ 的話,會報401 Unauthorized未授權錯誤,原因是 Hangfire 默認增加了授權配置。

解決方式:

增加CustomAuthorizeFilter

public class CustomAuthorizeFilter : IDashboardAuthorizationFilter
{
    public bool Authorize([NotNull] DashboardContext context)
    {
        //var httpcontext = context.GetHttpContext();
        //return httpcontext.User.Identity.IsAuthenticated;
        return true;
    }
}

Configure增加配置:

app.UseHangfireDashboard("/hangfire", new DashboardOptions() { 
    Authorization = new[] { new CustomAuthorizeFilter() }
});

參考資料:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM