Base solution for your next web application
Open Closed

How to impersonate tenant/user in code #9351


User avatar
0
TimMackey created

I want to enable a user to write records to multiple db tables that inherit AuditedEntity while impersonating another tenant/user. Assuming I have the target TenantId and UserId to be impersonated, how can I reference the IRepository repositories as the impersonated tenant/user such that the CreatorUserId recorded will be the impersonated UserId, and NOT the logged in UserId?

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

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

    hi timmackey

    You can try the following code

    using (abpSession.Use(tenantId, userId))
    {
    
    }
    
    using (CurrentUnitOfWork.SetTenantId(tenantId))
    {
    
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    TimMackey created

    The code above solved the issue.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)