相关文章: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() }
});
参考资料: