Açık Kapalı

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


User avatar
0
jmalla.cp oluşturuldu
  • 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 Cevap
  • User Avatar
    0
    maliming oluşturuldu
    Destek Takımı Fullstack Developer

    hi

    You can add userid to the background job parameters.

  • User Avatar
    0
    jmalla.cp oluşturuldu

    Hi,

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

  • User Avatar
    0
    maliming oluşturuldu
    Destek Takımı Fullstack Developer

    hi

    You can try:

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

    Great, thanks

Made with ❤️ on ABP v8.2.0-preview Updated on Mart 25, 2024, 15:11