I have created a new application using ASP.NET Core 6.0 Web API.
Implemented HangFire with basic authentication, everything works as expected locally, but after the deployment, Hangfire always returns an UnAuthorized
error.
Here is my Program.cs
file:
service.AddControllers();
service.AddEndpointsApiExplorer();
service.AddSwaggerExtension();
service.AddHangfire(configuration => configuration
.UseSimpleAssemblyNameTypeSerializer()
.UseRecommendedSerializerSettings()
.UseMemoryStorage());
service.AddHangfireServer();
service.AddHostedService<HangFireHostedService>();
service.AddSingleton<IChannelManager, ChannelManager>();
service.AddSingleton<IDataSourceManager, DataSourceManager>();
service.AddSingleton<IDataService, DataService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.UseHangfireDashboard("/hangfire", new DashboardOptions()
{
DashboardTitle = "Hangfire Dashboard",
IgnoreAntiforgeryToken = true,
Authorization = new[]{
new HangfireCustomBasicAuthenticationFilter{
User = app.Configuration["Hangfire:Username"],
Pass = app.Configuration["Hangfire:Password"]
}
}
});
app.MapControllers();
app.MapHangfireDashboard();
app.Run();