Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Hangfire - call tenant method - authorized #9244


User avatar
0
deltavision created

Hi,

using: Core, MVC, jQuery project - v7.2.2

Reference to #5755 - Specific the last comment.

We have a Hangfire job that is run for each tenant. When in UnitOfWork for the specific tenant - call to methods that are authorized fails (No user logged in)

  • As suggested in #5755 - run a job as a user or role?
  • "Disable" authorized check for hangfire job called through host.

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    You can refer to this reply. https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1107#issuecomment-226714736

  • User Avatar
    0
    deltavision created

    Hi maliming

    thank you - we have done it with the code below. To avoid "breaking" exsisting use of AppServices - we created a "HangfireUser" in each tenant, with the relevant roles/rights.

    var tenants = _tenantRepository.GetAll();
    foreach(var tenant in tenants)
    {
        using (CurrentUnitOfWork.SetTenantId(tenant.Id))
        {
            if (_featureChecker.IsEnabled(tenant.Id, AppFeatures.XYZ))
            {
                var tenantUser = _userManager.Users.FirstOrDefault(u => u.UserName.ToUpper() == "HangfireUser");
                if (tenantUser != null)
                {
                    using (_abpSession.Use(tenant.Id, tenantUser.Id))
                    {
                        // DO PROCESS...
    
  • User Avatar
    0
    deltavision created

    NB: also reference to #4115