Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HangFire in Azure Web App

I am using Hangfire as part of an ASP.NET MVC Website.

When I run the site locally, Hangfire works as expected. However, when I run Hangfire in the Production Environment (In Azure as a Web App), I am not able to access the Dashboard nor does it seem like the automatic jobs are running.

I initialize Hangfire entirely from the Status.cs:

public void Configuration(IAppBuilder Application)
{
      Application.CreatePerOwinContext<RepositoryManager>((x, y) => new RepositoryManager(new SiteDatabase(), x, y));
      Application.UseCookieAuthentication(new CookieAuthenticationOptions
      {
           CookieName = "Authentication",
           LoginPath = new PathString("/login"),
           AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
           Provider = new CookieAuthenticationProvider
           {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager, User, int>(
                     validateInterval: TimeSpan.FromMinutes(30),
                     regenerateIdentityCallback: (Manager, User) => User.GenerateClaimsAsync(Manager),
                     getUserIdCallback: (Claim) => int.Parse(Claim.GetUserId()))
           }
});

Application.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

GlobalConfiguration.Configuration
    .UseSqlServerStorage("platform_batch", new SqlServerStorageOptions { SchemaName = "dbo" })
    .UseDashboardMetric(SqlServerStorage.ActiveConnections)
    .UseDashboardMetric(SqlServerStorage.TotalConnections)
    .UseDashboardMetric(DashboardMetrics.FailedCount)
    .UseLogProvider<BatchLogProvider>(new BatchLogProvider())
    .UseFilter<AutomaticRetryAttribute>(new AutomaticRetryAttribute { Attempts = 0 });

Application.UseHangfireDashboard("/dashboard/global/batches",
    new DashboardOptions
    {
        AppPath = "/dashboard/global/overview",
        Authorization = new IDashboardAuthorizationFilter[] { new ContextRootAttribute(), new ContextStatusAttribute(StatusLevel.Owner) },
    });
    Application.UseHangfireServer(new BackgroundJobServerOptions { ServerName = Global.Property.Deployment.Environment.ToString() });

    RecurringJob.AddOrUpdate<BatchMinute>(x => x.Begin(), Cron.Minutely());
    RecurringJob.AddOrUpdate<BatchDay>(x => x.Begin(), Cron.Daily(2));
}

Again, this method works perfectly fine locally and in our staging environment (which runs on IIS), but doesn’t seem to work in our Azure Production Environment. Any ideas?

like image 285
William Avatar asked Oct 23 '25 22:10

William


1 Answers

I found this solution: To enable access use:

app.UseHangfireDashboard("hangfire", new DashboardOptions
{
    Authorization = Enumerable.Empty<IDashboardAuthorizationFilter>()
});
like image 63
yhorby matias Avatar answered Oct 25 '25 18:10

yhorby matias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!