我已經向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爲遲髮型儀表板解決方案應該工作以及