简体   繁体   中英

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?

I found this solution: To enable access use:

app.UseHangfireDashboard("hangfire", new DashboardOptions
{
    Authorization = Enumerable.Empty<IDashboardAuthorizationFilter>()
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM