我已经向Hangfire介绍了最近的内容,我必须说它非常棒。Azure WorkerRole或自托管应用程序中的Hangfire仪表板授权
我正在研究一个应用程序,其中我在Azure工作者角色中进行了hangfire。 一切正常完美;除了将授权配置为hangfire仪表板以外,它还包括hangfire配置,作业调度,仪表板等。
我已经添加了一个OwinStartup
类,在那里我配置了hangfire仪表板。我使用了我的自定义实现IAuthorizationFilter
和OwinMiddleware
,预计现在应提示用户在访问hangfire仪表板时提供凭据。但是没有任何帮助,并且在尝试访问仪表板时,它不断给我403
响应。 :(
如果在配置的仪表板,我不使用授权筛选选项,但当时每个人都可以访问它它的工作原理完全没有问题
这是我的启动类 -
public void Configuration(IAppBuilder app)
{
app.UseWelcomePage("/");
app.Use(typeof(AuthenticationMiddleware));
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
AuthorizationFilters = new[] { new MyAuthorization() }
});
}
我已经写OWIN中间件即AuthenticationMiddleware
的建议here
...和我的自定义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));
我想自托管applicatinon为迟发型仪表板解决方案应该工作以及