user2877820
user2877820

Reputation: 307

Hangfire doesnt work anymore after publishing the project

I'm working with ASP.NET MVC 5. .NET Framework has the version 4.5. After I published my Project, Hangfire doesnt work anymore. So my recurring Tasks wont work. When I enter www.{myurl}/Hangfire, I'm getting a blank site. The conenction String doesn't throw an error.

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(); 

So where could the problem be? When I run my project on localhost, it works fine. I'm using the same database on localhost and on my published version of the project.

Upvotes: 3

Views: 5547

Answers (2)

user4576114
user4576114

Reputation:

This is not good practice, but you can use the following code to allow all users

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

code from

Upvotes: 1

odinserj
odinserj

Reputation: 964

Remote requests to Hangfire Dashboard are denied by default – it is very simple to forget about authorization before publicating it to the production environment.

You can either use Hangfire.Dashboard.Authorization package to configure the authorization based on users, roles, claims or basic authentication; or create your own authorization filter as shown below.

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
    }
}

After creating authorization filter, register it:

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

Upvotes: 5

Related Questions