Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tiagocrizanto
Last active February 22, 2021 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagocrizanto/e3de12d6bfa145b981dfcc9fdc10217d to your computer and use it in GitHub Desktop.
Save tiagocrizanto/e3de12d6bfa145b981dfcc9fdc10217d to your computer and use it in GitHub Desktop.
// startup e configuração de autenticação
GlobalConfiguration.Configuration.UseSqlServerStorage(ConfigurationManager.ConnectionStrings["ConnectionsString"].ConnectionString);
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new[] { new HangfireSecurityFilter() }
});
app.UseHangfireServer();
// exemplo do filtro
public class HangfireSecurityFilter : IDashboardAuthorizationFilter
{
public bool Authorize(DashboardContext context)
{
// In case you need an OWIN context, use the next line, `OwinContext` class
// is the part of the `Microsoft.Owin` package.
var owinContext = new OwinContext(context.GetOwinEnvironment());
// Allow all authenticated users to see the Dashboard (potentially dangerous).
//return owinContext.Authentication.User.Identity.IsAuthenticated;
return true;
}
}
// Configuação de um job que executa a cada X minutos. RecurringJob Está no namespace Hangfire
public ActionResult AddMinuteJob(int minute)
{
RecurringJob.AddOrUpdate("Store-every-X-minutes", () => _myDomainServivice.MethodToExecute(), $"0/{minute} * * * *");
return RedirectToAction(nameof(Index));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment