簡體   English   中英

為什么hangfire儀表板在開發中工作而不在部署中工作

[英]why hangfire dashboard work in development and not work in deploy

這是訪問hangfire儀表板生產時的響應在此處輸入圖像描述

{"error":"The antiforgery system has the configuration value AntiforgeryOptions.Cookie.SecurePolicy = Always, but the current request is not an SSL request."}

這是使用的配置

services.AddHangfire(config => config
        .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
        .UseSimpleAssemblyNameTypeSerializer()
        .UseRecommendedSerializerSettings()
        .UseDefaultTypeSerializer()
        .UseSqlServerStorage(configuration.GetConnectionString("BackOffice")));;

        var sqlStorage = new SqlServerStorage(configuration.GetConnectionString("BackOffice"));
        JobStorage.Current = sqlStorage;
        services.AddHangfireServer();
        services.AddHttpClient();

您需要將 app.UseHangfireDashboard("/hangfire") 設置添加到您的 startup.cs 文件中。

注意這里的順序非常重要!

// This method gets called by the runtime. Use this 
method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, 
IBackgroundJobClient backgroundJobs, 
IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        }


    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", 
   "TheHockeyLabMn.WebApi v1"));

    app.UseHttpsRedirection();
        
    app.UseRouting();
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseElmah(); 
        app.UseHangfireDashboard("/hangfire", new 
     DashboardOptions
    {
        Authorization = new[] { new MyAuthorizationFilter() }
    });
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllers();
        endpoints.MapHangfireDashboard();

    });
}

您的過濾器應該是裸露的,我只是在這里設置 true 作為測試。

public class MyAuthorizationFilter : 
IDashboardAuthorizationFilter
 {
    public MyAuthorizationFilter()
    {

    }
    public bool Authorize(DashboardContext context)
    {
        var httpContext = context.GetHttpContext();

        // Allow all authenticated users to see the Dashboard (potentially dangerous).
        return true;//httpContext.User.Identity.IsAuthenticated;
    }
}

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM