asp.net-core - 如何在控制台应用程序中配置 hangfire 仪表板?

标签 asp.net-core console-application hangfire

我正在使用 hangfire nuget 包来安排 asp.net 核心控制台应用程序中的作业

我尝试了所有将仪表板配置到控制台应用程序的方法

我如何从控制台应用程序托管网页???

我已经为仪表板配置创建了 startup.cs 类

using Hangfire;
using Microsoft.AspNetCore.Builder;

    namespace PulsarHangFire
    {
        public class Startup
        {
            public void Configuration(IApplicationBuilder app)
            {
                app.UseHangfireDashboard("/hangfire");
                app.UseHangfireServer();
            }
        }
    }

谁能告诉我我该如何前进

最佳答案

创建一个 Startup.cs 文件(或从 .NET Core Web App 模板中获取一个文件)并配置以下内容:

public void ConfigureServices(IServiceCollection services)
{
    // ... other required services ...

    services.AddHangfire(configuration =>
    {
        // Do pretty much the same as you'd do with 
        // GlobalConfiguration.Configuration in classic .NET

        // NOTE: logger and activator would be configured automatically, 
        // and in most cases you don't need to configure those.

        configuration.UseSqlServerStorage(...);

        // ... maybe something else, e.g. configuration.UseConsole()
    });
}

最后添加 Hangfire 仪表板:

public void Configure(IApplicationBuilder app, IRecurringJobManager recurringJobManager)
{
    // ... previous pipeline stages, e.g. app.UseAuthentication()

    app.UseHangfireDashboard(...);

   // ... next pipeline stages, e.g. app.UseMvc()

   // then you may configure your recurring jobs here:
   recurringJobManager.AddOrUpdate(...);
}

Source

关于asp.net-core - 如何在控制台应用程序中配置 hangfire 仪表板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55292866/

相关文章:

asp.net-core - ArgumentNullException : String reference not set to an instance of a String. 参数名称 : s System. Text.Encoding.GetBytes(string s)

c# - Custom Tag Helper - 替换 html 标签

asp.net-core - 从.Net Core 2.2升级到3.0后,UserManager引发异常-无法跟踪实体,因为主键属性 'Id'为null

c# - 我应该先在文本模式下开发我的游戏创意吗?

c# - 在 Hangfire 中禁用 PreserveCultureAttribute

azure - asp.net core 2.0发布到azure得到IIS 502.5错误

c# - 在 c# 控制台应用程序中抑制控制台写入(来自其他组件)

c# - 密码屏蔽控制台应用程序

c# - 如何在控制台应用程序中成功运行 Hangfire MemoryStorage 作业?

c# - 配置在 Hangfire 上每 15 分钟执行一次的 cron 作业