首页 > 解决方案 > JobStorage.Current 属性值尚未初始化。您必须在使用 Hangfire 客户端或服务器 API 之前设置它

问题描述

我在 mvc 应用程序中使用 hangfire。我正在向用户发送他/她的约会提醒。我已经在我的应用程序中安装了hangfire。我在 startup.cs 类中配置了hangfire。但是当我运行该应用程序时,它会产生以下错误 JobStorage。当前属性值尚未初始化。您必须在使用 Hangfire 客户端或服务器 API 之前设置它。

using Hangfire;
using Hangfire.SqlServer;
using Microsoft.Owin;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UKC.Data.Infrastructure;
using UKC.UI.Helper;

[assembly: OwinStartup(typeof(UKC.UI.App_Start.Startup))]
namespace UKC.UI.App_Start
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            GlobalConfiguration.Configuration
               .UseSqlServerStorage("DbEntities");

            app.UseHangfireDashboard();
            app.UseHangfireServer();

        }
    }
}

标签: c#asp.net-mvchangfire

解决方案


用于在 Asp.net 核心中初始化

public static void InitializeHangFire()
        {
            var sqlStorage = new SqlServerStorage("connectionString");
            var options = new BackgroundJobServerOptions
            {
                ServerName = "Test Server"
            };
            JobStorage.Current = sqlStorage;
        }

推荐阅读