Open Closed

LastModifierId is not updating if calling from external service. #6298


User avatar
0
Priyanka created

I have one API which is called by external service and function in this service is AllowAnonymous. When user is calling this service we are taking user id as input to verify if user have rights to access the application, then on the service call we are updating one table in DB, I'm assigning LastModifierId as user id (which I received in input ) at the same time I'm assigning same user id in one more field (CCFLastModifierId), after successful update I found CCFLastModifierId is updated in DB but LastModifierId is not updating. Could you please help to understand the reason and how can I solve this problem.

I tried to assign the value by

  1. ObjectHelper.TrySetProperty(fc, x => x.LastModifierId, () => user.Id);
  2. tablename.LastModifierId= user.Id;

Both are not working.

ABP Framework version: v5.3.2

UI Type:React

Database System: EF Core (SQL Server)

Tiered (for MVC) or Auth Server Separated (for Angular): yes

Exception message and full stack trace:NA Call AllowAnonymous function from 3rd party and update few columns in table.


2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Because ABP uses the CurrentUser.Id as the LastModifierId value.

    You can try:

    private ICurrentPrincipalAccessor _currentPrincipalAccessor;
    
    ....
    
    
    var claims = new List<Claim>(){ new Claim(AbpClaimTypes.UserId,user.Id)};
    using(_currentPrincipalAccessor.Change(claims))
    {
        _repository.UpdateAsync(..., autoSave: true)
    }
    
  • User Avatar
    0
    Priyanka created

    Hi,

    Because ABP uses the CurrentUser.Id as the LastModifierId value.

    You can try:

    private ICurrentPrincipalAccessor _currentPrincipalAccessor; 
     
    .... 
     
     
    var claims = new List<Claim>(){ new Claim(AbpClaimTypes.UserId,user.Id)}; 
    using(_currentPrincipalAccessor.Change(claims)) 
    { 
        _repository.UpdateAsync(..., autoSave: true) 
    } 
    

    Thank you. It is updating now.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15