AbpSession.TenantId is not set when saving audit logs in background
See original GitHub issueHi guys,
I’am having an intermittent issue where AbpSession.TenantId
is not set, even thought that client is sending the correct TenantId per request.
code behind GetItem:
public async Task<AdDto> GetItem(GetAdInput input)
{
var culture = await _applicationLanguageRepository.GetCultureAsync(AbpSession.TenantId);
var sessionId = Extensions.GetGuid(input.SessionId);
var ad = await _adRepository.SingleOrDefaultAsync(input.AdId, sessionId, AbpSession.UserId, input.IsEdit, culture.TwoLetterISOLanguageName);
if (ad == null)
{
throw new UserFriendlyException("There is no such an ad.");
}
if (ad.TenantId != AbpSession.TenantId && ad.TenantId.HasValue)
{
throw new UserFriendlyException("Tenant session is not valid.");
}
if (ad.Status == AdStatus.Active)
{
ad.Slug = ad.Title.GenerateSlug();
}
var adOutput = ad.MapTo<AdDto>();
}
As you can see in the image below that the first request for GetItem?AdId=1000021352&isEdit=false
was succeed without error but the second request failed with the error Tenant session is not valid
Abp version: V4.0.0
Template base: .Net Framework
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
set tenant Session #6269
SaveAsync() is called. At this stage AbpSession is null. The result is that the audit log gets written to the audit log for...
Read more >How to assign TenantId to abpsession in login process API?
For login used TokenAuthController/Authenticate as post request, it's logging but cannot be getting the Tenant details there. As the AbpSession.
Read more >Audit Logging | Documentation Center | ABP.IO
Wikipedia: "An audit trail (also called audit log) is a security-relevant chronological record, set of records, and/or destination and source of records ...
Read more >Overriding Current Session Values
Introduction. ASP.NET Boilerplate provides an IAbpSession interface to obtain the current user and tenant without using ASP.NET's Session.
Read more >Custom Audit Log Entries not saving/creating #9830
I have a custom Audit class as below. When I try to call and save to the Audit log no audit data si...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is indeed due to an error caused by RunInBackground. Of course this problem is not easy to find because it does not cause a task exception log.
The problem is in the class
HttpContextTenantResolverCache
. My understanding is that the background thread incorrectly sets the contents ofhttpContext.Items [CacheItemKey]
Causes random problems that cannot readTenandId
correctly.https://github.com/aspnetboilerplate/aspnetboilerplate/blob/e0ded5d8702f389aa1f5947d3446f16aec845287/src/Abp.AspNetCore/AspNetCore/MultiTenancy/HttpContextTenantResolverCache.cs#L7
If someone can share specific details inside, I am very interested to learn. 🙂
@armory09 Sorry, I have reproduced the problem you have encountered, please wait a moment.