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

时间:2016-06-28 16:03:31

标签: asp.net iis owin hangfire

我无法让Hangfire(1.5.8)信息中心在IIS Virtual Directoy中运行。在我的开发环境中,一切都运行得很漂亮,我的应用程序只是映射到localhost的根目录。另一方面,我们的测试版服务器使用虚拟目录来分隔应用程序和应用程序池。

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

为了解决这个问题,我的IAuthenticationFilter只返回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中间件管理工具可以用来深入了解在IIS中注册的URL?

3 个答案:

答案 0 :(得分:2)

我最终只是通过将HTTPHandler添加到web.config中的部分来修复此问题。

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

答案 1 :(得分:0)

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

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

希望这有帮助。

马丁

答案 2 :(得分:0)

我在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