BZink
BZink

Reputation: 7967

Hangfire.io Dashboard mapped to IIS Virtual Directory

I'm having trouble getting the Hangfire (1.5.8) dashboard to work inside of an IIS Virtual Directoy. Everything works beautifully in my dev environment where my application is simply mapped to the root of localhost. Our beta server, on the other hand, uses Virtual Directories to separate apps and app pools.

It's an ASP.Net MVC site using Hangfire with an OWIN Startup class. It gets deployed to http://beta-server/app-name/. When I attempt to access either http://beta-server/app-name/hangfire or http//beta-server/hangfire I get a 404 from IIS.

For the purposes of troubleshooting this, my IAuthenticationFilter simply returns true.

Here is my Startup.cs, pretty basic:

public class Startup
  {
    public void Configuration(IAppBuilder app)
    {
      // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888

      GlobalConfiguration.Configuration
        .UseSqlServerStorage(new DetectsEnvironment().GetEnvironment());

      app.UseHangfireDashboard("/hangfire", new DashboardOptions
      {
        AuthorizationFilters = new[] {new AuthenticationFilter()}
      });
      app.UseHangfireServer();

    }
  }

Does anyone have a working implementation that gets deployed to a Virtual Directory? Are there any OWIN middleware admin/management tools I can use to dig into what URL is getting registered within IIS?

Upvotes: 5

Views: 2739

Answers (3)

Alexei - check Codidact
Alexei - check Codidact

Reputation: 23078

I had a similar issue in ASP.NET Core 2.0 and it required proper authorization setup (I use a middleware to protect the route, so I did not rely on authorization in my example):

app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
    Authorization = new [] {new HangfireDashboardAuthorizationFilter()}
});

/// <summary>
/// authorization required when deployed
/// </summary>
public class HangfireDashboardAuthorizationFilter : IDashboardAuthorizationFilter
{
    ///<inheritdoc/>
    public bool Authorize(DashboardContext context)
    {
        // var httpContext = context.GetHttpContext();

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

There is not need to change anything in web.config.

For more information check Hangfire documentation about this topic.

Upvotes: 1

BZink
BZink

Reputation: 7967

I ended up fixing this simply by adding the HTTPHandler to the section in web.config.

<system.webServer>
<handlers>
<add name="hangfireDashboard" path="hangfire" type="System.Web.DefaultHttpHandler" verb="*" />
</handlers>
</system.webServer>

Upvotes: 2

Martin Brabec
Martin Brabec

Reputation: 3850

I had the exact same problem. In my case, this was because of bad configuration - the Startup class was not called. So try to add the following to your config file:

<add key="owin:appStartup" value="YourProject.YourNamespace.Startup, YourProject" />
<add key="owin:AutomaticAppStartup" value="true" />

Hope this helps.

Martin

Upvotes: 0

Related Questions