c# - 多台服务器在 HANGFIRE 中生成错误 500
问题描述
当我使用 pod 管理的 Kubernetes 架构将应用程序投入生产时,它具有扩展的可能性,因此今天它有两台服务器运行相同的应用程序,hangfire 识别两者但返回错误 500
Unable to refresh the statistics: the server responded with 500 (error). Try reloading the page manually, or wait for automatic reload that will happen in a minute.
但是当我离开只有一台服务器的测试应用程序的舞台时,hangfire 工作正常。
挂火配置:
Startup.cs
services.AddHangfire(x => x.UsePostgreSqlStorage(Configuration.GetConnectionString("DefaultConnection")));
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new[] { new AuthorizationFilterHangfire() }
});
app.UseHangfireServer();
解决方案
您现在可以添加IgnoreAntiforgeryToken
到您的服务中,这应该可以解决此问题。
根据this github post,当您有多个服务器运行仪表板时会出现问题,并且由于负载平衡,当您的请求与最初获得页面的服务器不同时,您会看到错误。
添加IgnoreAntiforgeryToken = true
到仪表板应该可以解决问题。
摘自这里
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new[] {new HangfireAuthFilter()},
IgnoreAntiforgeryToken = true // <--This
});
推荐阅读
- wordpress - 如何在任何 WordPress 中创建 5 列行
- firebase - 如何将 Firebase 存储与自定义服务器一起使用?
- python - 删除外部循环中的增量不会改变输出,但是内部循环会改变
- apache-spark - 如何共享全球火花会话?
- javascript - 如何使用同一类的多个 HTML 标记的内容构建一个数组?
- mysql - mysql查询中面临的问题
- excel - 从 Excel 文件中读取日期会将其转换为类似 32509.0 的数字
- javascript - 在 vue 组件中使用 this.$root 有什么缺点?
- c# - TagBuilder AddCssClass 顺序,添加到开头,末尾如何添加新类?
- ios - 如何快速刷新 Firebase 推送通知