Настройка глобального фильтра запросов в ядре 6C#

Место общения программистов C#
Ответить
Гость
 Настройка глобального фильтра запросов в ядре 6

Сообщение Гость »


Brief: I'm facing a problem with setting Global Query Filter using Claim added to signed user. Error scenario: when signing in ef core is still not loaded so

Код: Выделить всё

OnModelCreating
function is triggered that contains the configuration of my entities where I set Global Query Filter using tenant id claim using this function

Код: Выделить всё

    private long GetRequestTenantId()     {         try         {             var tenantClaim = contextAccessor.HttpContext.User.Claims.Where(c => c.Type == "TenantId").FirstOrDefault();             if (tenantClaim == null)                 return 0;                          bool IsParsed = long.TryParse(tenantClaim.Value, out long tenantId);             if (!IsParsed)                 return 0;             return tenantId;         }         catch (Exception ex)         {             return 0;         }     } 
which naturally return on first run. Is there any other way to set Global Query Filter to fix this problem? What I tried to do was sert query filter according to the user that sent the request. which works fine when I relaunch the application and happens again when the session ends and I log in again.


Источник: https://stackoverflow.com/questions/781 ... -ef-core-6
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»