Hangfire.io 仪表板映射到 IIS 虚拟目录

Hangfire.io Dashboard mapped to IIS Virtual Directory

我无法让 Hangfire (1.5.8) 仪表板在 IIS 虚拟目录中工作。在我的开发环境中,一切都运行得很好,我的应用程序被简单地映射到本地主机的根目录。另一方面,我们的测试版服务器使用虚拟目录来分隔应用程序和应用程序池。

这是一个 ASP.Net MVC 站点,使用 Hangfire 和 OWIN Startup class。它被部署到 http://beta-server/app-name/。当我尝试访问 http://beta-server/app-name/hangfirehttp//beta-server/hangfire 时,我从 IIS 收到 404。

为了对此进行故障排除,我的 IAuthenticationFilter 只是 returns true。

这是我的 Startup.cs,非常基本:

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();

    }
  }

有人有部署到虚拟目录的有效实施吗?是否有任何 OWIN 中间件 admin/management 工具可用于深入了解 URL 在 IIS 中注册的内容?

我遇到了完全相同的问题。在我的例子中,这是因为配置错误 - 未调用 Startup class。因此,请尝试将以下内容添加到您的配置文件中:

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

希望对您有所帮助。

马丁

我最终通过将 HTTPHandler 添加到 web.config 中的部分来解决这个问题。

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

我在 ASP.NET Core 2.0 中遇到了类似的问题,它需要正确的授权设置(我使用中间件来保护路由,所以我在示例中不依赖授权):

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;
    }
}

web.config.

中无需更改任何内容

有关详细信息,请查看 Hangfire documentation about this topic