Featured
Hangfire in .NET 6 – Background Jobs Made Easy
Last modified: March 19, 2022Why we need Hangfire?
There are couple of possible reason; no access to server (therefore no task schedular), able to manage/view jobs in Web UI.
1. Create Project
Create an ASP.NET MVC application.
2. Install Hangfire
Right click the project and click Manage NuGet package
Install below packages
- Hangfire.Core
- Hangfire.SqlServer
- Hangfire.AspNetCore
3. Create a database
- Login to SQL Mangement Studio
- Create a database
4. Configure Settings
- Add Database Connection string to appsettings.json file
- Program.cs
5. Jobs
6. View Dashboard
domain.com/hangfire
Secure dashboard
program.cs
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
DashboardTitle = "My Website",
Authorization = new[]
{
new HangfireCustomBasicAuthenticationFilter{
User = builder.Configuration.GetSection("HangfireSettings:UserName").Value,
Pass = builder.Configuration.GetSection("HangfireSettings:Password").Value
}
}
});
appsettings.json
"HangfireSettings": {
"UserName": "admin",
"Password": "password"
}