Base solution for your next web application
Open Closed

Error accessing Hangfire Dashboard #3798


User avatar
0
ervingayle created

I am sorry if this is a duplicate post. I thought I had a post for this already but cannot find it and the issue is not resolved.

I am receive the following error after uncommenting the lines for Hangfire. The hangfire tables have been created and jobs are working but I am unable to access the dashboard. I am not using token authentication. Does anyone have this working in 4.4 .net core?

ArgumentException: Context argument should be of type AspNetCoreDashboardContext! Parameter name: context Hangfire.Dashboard.AspNetCoreDashboardContextExtensions.GetHttpContext(DashboardContext context)

My configure method: private static void ConfigureOwinServices(IAppBuilder app) { app.Properties["host.AppName"] = "Vnext";

        app.UseAbp();

        app.MapSignalR();

        //Enable it to use HangFire dashboard (uncomment only if it's enabled in VnextWebCoreModule)
        app.UseHangfireDashboard("/hangfire", new DashboardOptions
        {
            Authorization = new[] { new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) }
            //Authorization = new[] { new AbpHangfireAuthorizationFilter() }
        });
    }

7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ervingayle,

    Have you upgraded hangfire or is it just the one comes with AspNet Zero ?

    Thanks.

  • User Avatar
    0
    ervingayle created

    Hello,

    I have not upgraded the hangfire packages.

    It is the one which comes with AspNet Zero.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you have uncommented wrong part of enabling hangfire dashboard code. If you are using .Net Core, the code you shared will not work.

    Can you try to enable app.UseHangfireDashboard in Configure method of Startup.cs ?

    I have tried and it seems like it shows hangfire dashboard but I haven't created any hangfire jobs.

    Thanks.

  • User Avatar
    0
    ervingayle created

    Thanks for your reply. The startup.cs in the .net core version has two Configure methods. I have uncommneted the Hangfire lines in each and then one by one and did not have success but maybe I am missing something as you mentioned. Here is the complete file.

    #if FEATURE_SIGNALR using Owin; using Abp.Owin; using ProjectName.Web.Owin; #endif

    namespace ProjectName.Web.Startup { public class Startup { private readonly IConfigurationRoot _appConfiguration;

        public Startup(IHostingEnvironment env)
        {
            _appConfiguration = env.GetAppConfiguration();
        }
    
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //MVC
            services.AddMvc(options =>
            {
                options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
            });
    
            IdentityRegistrar.Register(services, "Application");
    
            //Identity server
            if (bool.Parse(_appConfiguration["IdentityServer:IsEnabled"]))
            {
                IdentityServerRegistrar.Register(services, _appConfiguration);
            }
    
            //Swagger - Enable this line and the related lines in Configure method to enable swagger UI
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info { Title = "EnotchVnext API", Version = "v1" });
                options.DocInclusionPredicate((docName, description) => true);
            });
    
            //Recaptcha
            services.AddRecaptcha(new RecaptchaOptions
            {
                SiteKey = _appConfiguration["Recaptcha:SiteKey"],
                SecretKey = _appConfiguration["Recaptcha:SecretKey"]
            });
    
            //Hangfire (Enable to use Hangfire instead of default job manager)
            services.AddHangfire(config =>
            {
                config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default"));
            });
    
            services.AddScoped<IWebResourceManager, WebResourceManager>();
    
            //Configure Abp and Dependency Injection
            return services.AddAbp<EnotchVnextWebMvcModule>(options =>
            {
                //Configure Log4Net logging
                options.IocManager.IocContainer.AddFacility<LoggingFacility>(
                    f => f.UseAbpLog4Net().WithConfig("log4net.config")
                );
            });
        }
    
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            //Initializes ABP framework.
            app.UseAbp(options =>
            {
                options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
            });
    
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseDeveloperExceptionPage();
                //Commented error pages
                //app.UseStatusCodePagesWithRedirects("~/Error?statusCode={0}");
                //app.UseExceptionHandler("/Error");
            }
    
            AuthConfigurer.Configure(app, _appConfiguration);
    
            app.UseStaticFiles();
    
            app.UseAbpRequestLocalization();
    

    #if FEATURE_SIGNALR //Integrate to OWIN app.UseAppBuilder(ConfigureOwinServices); #endif

            //Hangfire dashboard & server (Enable to use Hangfire instead of default job manager)
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            {
                Authorization = new[] { new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) }
            });
            app.UseHangfireServer();
    
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{area}/{controller=Home}/{action=Index}/{id?}");
    
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
    
            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger();
            //Enable middleware to serve swagger - ui assets(HTML, JS, CSS etc.)
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "EnotchVnext API V1");
            }); //URL: /swagger
        }
    

    #if FEATURE_SIGNALR private static void ConfigureOwinServices(IAppBuilder app) { app.Properties["host.AppName"] = "EnotchVnext";

            app.UseAbp();
    
            app.MapSignalR();
    
            //Enable it to use HangFire dashboard (uncomment only if it's enabled in EnotchVnextWebCoreModule)
            //app.UseHangfireDashboard("/hangfire", new DashboardOptions
            //{
            //    Authorization = new[] { new AbpHangfireAuthorizationFilter(AppPermissions.Pages_Administration_HangfireDashboard) }
            //    //Authorization = new[] { new AbpHangfireAuthorizationFilter() }
            //});
        }
    

    #endif } }

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ervingayle,

    Do you use angular version ? If so, this might not work, I'm not sure if hangfire supports bearer token auth, see #3769.

    If it is not angular, can you share your project with us and let us check it.

    Thanks.

  • User Avatar
    0
    ervingayle created

    Unfortunately, I am using .net core (Full Framework) with jQuery. I am on version 4.4 at the moment. Will wait until the next version to upgrade to the latest release as I would like to test the IdentityServer integration

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ervingayle,

    As I mentioned, if you couldn't make it work, you can send your project to us via email (<a href="mailto:[email protected]">[email protected]</a>) and we will take a look at your problem if you like.

    Thanks.