【发布时间】:2016-01-13 12:44:14
【问题描述】:
这是我最近才介绍给 Hangfire 的,我必须说它很棒。
我正在开发一个应用程序,其中我以 Azure 工作者角色托管 hangfire。 一切都很完美; hangfire 配置、作业调度、仪表板等。除了配置hangfire 仪表板的授权。
我添加了一个OwinStartup 类,我在其中配置了hangfire 仪表板。我使用了IAuthorizationFilter 和OwinMiddleware 的自定义实现,预计现在应该提示用户在访问hangfire 仪表板时提供凭据。但没有任何帮助,它在尝试访问仪表板时不断给我403 响应。 :(
如果我在配置仪表板时不使用授权过滤器选项,它工作得很好,但是每个人都可以访问它。
这是我的 Startup 课程 -
public void Configuration(IAppBuilder app)
{
app.UseWelcomePage("/");
app.Use(typeof(AuthenticationMiddleware));
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
AuthorizationFilters = new[] { new MyAuthorization() }
});
}
我已经按照here的建议编写了 OWIN 中间件,即AuthenticationMiddleware
...还有我的自定义IAuthorizationFilter
public class MyAuthorization : IAuthorizationFilter
{
public bool Authorize(IDictionary<string, object> owinEnvironment)
{
var context = new OwinContext(owinEnvironment);
// Allow all authenticated users to see the Dashboard
return context.Authentication.User.Identity.IsAuthenticated;
}
}
这就是我在工作角色的OnStart 方法中配置仪表板的方式。 (ref)
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WorkerRoleEndpoint"];
string baseUri = String.Format("{0}://{1}", endpoint.Protocol, endpoint.IPEndpoint);//http://127.0.0.1:81/hangfire
owinApp = WebApp.Start<HangfireDashboardStartup>(new StartOptions(url: baseUri));
我猜自托管应用程序中的hangfire仪表板解决方案应该也可以工作
【问题讨论】:
标签: c# azure-worker-roles hangfire