Fork me on GitHub

解决 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() }
});

参考资料:

posted @ 2017-06-20 17:26  田园里的蟋蟀  阅读(5773)  评论(1编辑  收藏  举报