Open Closed

How can I change the current user in a background service #5467


User avatar
0
jmalla.cp created
  • ABP Framework version: v6.0.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Auth Server Separated (Angular): Tired
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

Hi,

Now we are running some processes within a background service, and we need to know which person runs this process. However, when the background service runs the process, it doesn't know the user who launched the background service.

How can I set the user who ran the background service as the current user within the background service?

Thanks


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can add userid to the background job parameters.

  • User Avatar
    0
    jmalla.cp created

    Hi,

    Yes, I know. But then how can I load the current user from userId?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try:

    using (CurrentPrincipalAccessor.Change(new Claim(AbpClaimTypes.UserId, userid)))
    {
        //...
    }
    
  • User Avatar
    0
    jmalla.cp created

    Great, thanks

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09