So I have Hangfire inside a console app that runs a background job simultaneously. I wanted to check the dashboard on the hangfire but it never appeared to me. Hangfire is executing well.
builder.ConfigureServices(services =>
{
.....
services.AddHangfire((provider, configuration) =>
{
var dbOptions = provider.GetRequiredService<IOptions<DatabaseOptions>>().Value;
configuration.UsePostgreSqlStorage(dbOptions.Postgres.ConnectionString);
});
services.AddHangfireServer();
}).ConfigureWebHostDefaults(builder =>
{
builder.Configure(app =>
{
app.UseRouting();
app.UseMvc();
app.UseHangfireDashboard("/hangfire", new
DashboardOptions
{
Authorization = new[] { new AuthorizationFilter() }
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHangfireDashboard();
});
});
});
var host = builder.Build();
await host.RunAsync();
I tried to access localhost:5000/hangire but no luck. My Authorization filter is this one:
public class AuthorizationFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
return true;
}
}
Does anyone have any hints?
I have figure it out for
.net8.UPDATE : Same example works for
.net6First in your
csprojadd this :Then in my
Program.cs:I thing that you were missing just include of
Microsoft.AspNetCore.App.NOTE : I'm using
SQL Serveras persistance because I have already hangfire database ready.NOTE 2: Maybe it would be easier to have hangfire server configured as part of
.NET SDK Workerand Dashboard UI inside the WebAPI.. Not sure what your use case is.