相關文章: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() }
});
參考資料:
