You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 8+Hangfire 1.8.5 无法正确设置仪表盘中文语言

Hangfire仪表盘中文显示问题解决(.NET Core 8.0 + Hangfire 1.8.5)

问题原因

Hangfire默认不包含中文本地化资源,仅靠ASP.NET Core的请求本地化配置无法让仪表盘切换为中文,需要单独安装中文语言包并配置仪表盘的文化选项。

解决步骤

  1. 安装Hangfire中文语言包
    通过NuGet安装Hangfire.Dashboard.Localization.Zh-CN:
dotnet add package Hangfire.Dashboard.Localization.Zh-CN
  1. 调整仪表盘配置
    修改UseHangfireDashboard的调用,显式指定仪表盘的文化信息,同时确保UseRequestLocalization中间件在仪表盘之前执行(你的现有代码顺序已符合要求):

完整启动配置代码:

// 注册Hangfire服务
services.AddHangfire(configuration => configuration
    .SetDataCompatibilityLevel(CompatibilityLevel.Version_180)
    .UseSimpleAssemblyNameTypeSerializer()
    .UseRecommendedSerializerSettings()
    .UseInMemoryStorage());

services.AddHangfireServer();

// 配置请求本地化
var supportedCultures = new[] { "zh-CN" };
app.UseRequestLocalization(options =>
{
    options
        .AddSupportedCultures(supportedCultures)
        .AddSupportedUICultures(supportedCultures)
        .SetDefaultCulture("zh-CN")
        .RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(context =>
        {
            return Task.FromResult(new ProviderCultureResult("zh-CN"));
        }));
});

// 配置带中文本地化的Hangfire仪表盘
app.UseHangfireDashboard("/job", new DashboardOptions
{
    Culture = "zh-CN",
    UiCulture = "zh-CN"
});

验证

重启应用后访问/job路径,仪表盘应该会显示为中文。如果仍有问题,检查语言包是否正确安装,以及项目是否引用了对应的本地化资源。

内容的提问来源于stack exchange,提问作者MR.Zhang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 14:14:54