在Azure Web App中使用HangFire

时间:2018-02-27 16:10:39

标签: asp.net asp.net-mvc hangfire

我使用Hangfire作为ASP.NET MVC网站的一部分。

当我在本地运行网站时,Hangfire按预期工作。但是,当我在生产环境中运行Hangfire时(在Azure中作为Web应用程序),我无法访问仪表板,也不会看起来自动作业正在运行。

我完全从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));
}

同样,这种方法在本地和我们的登台环境(在IIS上运行)中运行得非常好,但似乎在我们的Azure生产环境中不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我找到了这个解决方案: 要启用访问权限,请执行以下操作:

apples