I am currently experiencing a strange issue with our Hangfire implementation - only on deployment to our higher environment however. When I try to access the Dashboard URL I receive a “System.Web.HttpException (0x80004005): The controller for path ‘/jobs’ was not found or does not implement IController.”. I have tried a number of changes to get the route to be picked up - and have also tried specifically ignoring the route to see if that resolved the issue but to no avail.
My Startup Class Code is below;
[assembly: OwinStartup(typeof(HubPortal.Web.Startup))]
namespace MyApp.Web
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
try
{
//addition of Hangfire startup calls
GlobalConfiguration.Configuration.UseSqlServerStorage("ScheduledJobs");
GlobalConfiguration.Configuration.UseActivator(
new UnityJobActivator(UnityConfig.ConstructStandAloneContainer<PerResolveLifetimeManager>()));
app.UseHangfireDashboard();
app.UseHangfireDashboard("/jobs", new DashboardOptions
{
AuthorizationFilters = new[] { new HangfireAuthorizationFilter() }
});
app.UseHangfireServer();
RecurringJob.AddOrUpdate<ScheduledJobsHandler>(x => x.MySpecialJob(), Cron.Daily(2, 0));
}
catch (Exception ex)
{
//Issue loading Hangfire control
}
}
}
}
My Authorization Filter is below (to be extended to administrators only once I can get the Dash working);
using System.Collections.Generic;
using Hangfire.Dashboard;
using Microsoft.Owin;
namespace HubPortal.Web.AuthorizationFilters
{
public class HangfireAuthorizationFilter : IAuthorizationFilter
{
public bool Authorize(IDictionary<string, object> owinEnvironment)
{
// In case you need an OWIN context, use the next line,
// OwinContext
class is the part of the Microsoft.Owin
package.
var context = new OwinContext(owinEnvironment);
// Allow all authenticated users to see the Dashboard (potentially dangerous).
return context.Authentication.User.Identity.IsAuthenticated;
}
}
}
Has anyone encountered this issue before? It also fails if I don’t try a custom route to the dashboard and just take the default route.
Any help would be greatly appreciated.
Thanks,
Jamie