简体   繁体   English

在 Azure Web 应用程序中使用 HangFire

[英]Using HangFire in Azure Web App

I am using Hangfire as part of an ASP.NET MVC Website.我正在使用 Hangfire 作为 ASP.NET MVC 网站的一部分。

When I run the site locally, Hangfire works as expected.当我在本地运行站点时,Hangfire 会按预期工作。 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.但是,当我在生产环境中运行 Hangfire(在 Azure 中作为 Web 应用程序)时,我无法访问仪表板,自动作业似乎也没有运行。

I initialize Hangfire entirely from the Status.cs:我完全从 Status.cs 初始化 Hangfire:

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.同样,此方法在本地和我们的暂存环境(在 IIS 上运行)中工作得很好,但在我们的 Azure 生产环境中似乎不起作用。 Any ideas?有任何想法吗?

I found this solution: To enable access use:我找到了这个解决方案:要启用访问权限,请使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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