2014-12-19 153 views
2

我正在使用ASP.NET MVC 5. .NET Framework的版本爲4.5。 當我發佈我的項目後,Hangfire不再工作。所以我的循環任務不會工作。當我輸入www。{myurl}/Hangfire時,我得到一個空白網站。 conenction字符串不會引發錯誤。發佈項目後,Hangfire不再工作

config.UseSqlServerStorage("Server={myServer}.database.windows.net,1433;Database={myDatabase};User ID={myUserId};Password={MyPassword};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"); 
config.UseServer(); 

那麼問題出在哪裏呢?當我在localhost上運行我的項目時,它工作正常。 我在本地和項目的已發佈版本上使用相同的數據庫。

回答

5

默認拒絕對Hangfire儀表板的遠程請求 - 在將其發佈到生產環境之前,忘記授權是非常簡單的。

您可以使用Hangfire.Dashboard.Authorization包來配置基於用戶,角色,聲明或基本身份驗證的授權;或者創建您自己的授權過濾器,如下所示。

using Hangfire.Dashboard; 

public class MyRestrictiveAuthorizationFilter : IAuthorizationFilter 
{ 
    public bool Authorize(IDictionary<string, object> owinEnvironment) 
    { 
     // In case you need an OWIN context, use the next line. 
     // `OwinContext` class is defined in the `Microsoft.Owin` package. 
     var context = new OwinContext(owinEnvironment); 

     return false; // or `true` to allow access 
    } 
} 

創建授權過濾器後,其註冊:

app.UseHangfire(config => 
{ 
    config.UseAuthorizationFilters(new MyRestrictiveAuthorizationFilter()); 
}); 
1

這不是很好的做法,但你可以使用下面的代碼,允許所有用戶

app.UseHangfire(config => 
{ 
    config.UseAuthorizationFilters(); //allow all users to access the dashboard 
}); 

代碼from