using Owin;
using Microsoft.Owin;
using Hangfire;
using Hangfire.SqlServer;
using Hangfire.Dashboard;
// Task namespace
using WebpartService.Tasks;
[assembly: OwinStartup(typeof(WebpartService.Startup))]
namespace WebpartService
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var storage = new SqlServerStorage("HangFireConnectionString");
GlobalConfiguration.Configuration.UseStorage(storage);
RecurringJob.AddOrUpdate(t => t.Run(), Cron.Hourly);
var options = new DashboardOptions();
var filter = new BasicAuthAuthorizationFilter(
new BasicAuthAuthorizationFilterOptions
{
// Require secure connection for dashboard
RequireSsl = false,
SslRedirect = false,
// Case sensitive login checking
LoginCaseSensitive = true,
// Users
Users = new[]
{
new BasicAuthAuthorizationUser
{
Login = "administrator",
// Password as plain text
PasswordClear = "asdf"
}
}
});
options.AuthorizationFilters = new IAuthorizationFilter[] { filter };
app.UseHangfireDashboard("/hangfire", options);
app.UseHangfireServer();
}
}
}
49400cookie-checkC# – Hangfire background tasks