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

问题描述 投票:4回答:3

我无法让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?

asp.net iis owin hangfire
3个回答
2
投票

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

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

0
投票

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

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

希望这可以帮助。

马丁


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

© www.soinside.com 2019 - 2024. All rights reserved.