hi
Can you also override the ICachedApplicationConfigurationClient and test again?
using System;
using System.Globalization;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ClientProxies;
using Volo.Abp.AspNetCore.Mvc.Client;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
using Volo.Abp.Users;
namespace My.Web.Public;
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(ICachedApplicationConfigurationClient))]
public class MvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
private const string HttpContextItemsCacheKeyFormat = "ApplicationConfigurationDto_{0}_{1}_CacheKey";
protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
protected AbpApplicationLocalizationClientProxy ApplicationLocalizationClientProxy { get; }
protected ICurrentUser CurrentUser { get; }
protected MvcCachedApplicationConfigurationClientHelper CacheHelper { get; }
protected IDistributedCache<ApplicationConfigurationDto> Cache { get; }
protected AbpAspNetCoreMvcClientCacheOptions Options { get; }
public MvcCachedApplicationConfigurationClient(
MvcCachedApplicationConfigurationClientHelper cacheHelper,
IDistributedCache<ApplicationConfigurationDto> cache,
AbpApplicationConfigurationClientProxy applicationConfigurationAppService,
ICurrentUser currentUser,
IHttpContextAccessor httpContextAccessor,
AbpApplicationLocalizationClientProxy applicationLocalizationClientProxy,
IOptions<AbpAspNetCoreMvcClientCacheOptions> options)
{
ApplicationConfigurationAppService = applicationConfigurationAppService;
CurrentUser = currentUser;
HttpContextAccessor = httpContextAccessor;
ApplicationLocalizationClientProxy = applicationLocalizationClientProxy;
Options = options.Value;
CacheHelper = cacheHelper;
Cache = cache;
}
public virtual async Task<ApplicationConfigurationDto> GetAsync()
{
string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext;
var itemsKey = GetHttpContextItemsCacheKey();
if (httpContext != null && httpContext.Items[itemsKey] is string key)
{
cacheKey = key;
}
if (cacheKey.IsNullOrWhiteSpace())
{
cacheKey = await CreateCacheKeyAsync();
if (httpContext != null)
{
httpContext.Items[itemsKey] = cacheKey;
}
}
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
configuration = (await Cache.GetOrAddAsync(
cacheKey,
async () => await GetRemoteConfigurationAsync(),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = Options.ApplicationConfigurationDtoCacheAbsoluteExpiration
}
))!;
if (httpContext != null)
{
httpContext.Items[cacheKey] = configuration;
}
return configuration;
}
private async Task<ApplicationConfigurationDto> GetRemoteConfigurationAsync()
{
var config = await ApplicationConfigurationAppService.GetAsync(
new ApplicationConfigurationRequestOptions
{
IncludeLocalizationResources = false
}
);
var localizationDto = await ApplicationLocalizationClientProxy.GetAsync(
new ApplicationLocalizationRequestDto {
CultureName = config.Localization.CurrentCulture.Name,
OnlyDynamics = true
}
);
config.Localization.Resources = localizationDto.Resources;
return config;
}
public ApplicationConfigurationDto Get()
{
string? cacheKey = null;
var httpContext = HttpContextAccessor?.HttpContext;
var itemsKey = GetHttpContextItemsCacheKey();
if (httpContext != null && httpContext.Items[itemsKey] is string key)
{
cacheKey = key;
}
if (cacheKey.IsNullOrWhiteSpace())
{
cacheKey = AsyncHelper.RunSync(CreateCacheKeyAsync);
if (httpContext != null)
{
httpContext.Items[itemsKey] = cacheKey;
}
}
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
return AsyncHelper.RunSync(GetAsync);
}
protected virtual async Task<string> CreateCacheKeyAsync()
{
return await CacheHelper.CreateCacheKeyAsync(CurrentUser.Id);
}
protected virtual string GetHttpContextItemsCacheKey()
{
return string.Format(CultureInfo.InvariantCulture, HttpContextItemsCacheKeyFormat, CurrentUser.Id?.ToString("N") ?? "Anonymous", CultureInfo.CurrentUICulture.Name);
}
}
We make the same changes on https://github.com/abpframework/abp/pull/24990
Thanks.
hi
https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems
var loggerConfiguration = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Async(c => c.File("Logs/logs.txt"))
Thanks.
hi
You can disable the CheckLibs, It won't affect anything, just remeind developer to run the install-libs command
Configure<AbpMvcLibsOptions>(options =>
{
options.CheckLibs = false;
});
Thanks.
hi
Can you enable debug logging and share the full logs.txt file at the time of the error?
https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems
Thanks
hi
I think your slow problem is probably not related to returning all the JSON, because a delay of 30-40 seconds is unlikely to be caused by that.
It's most likely that the delay was caused by the database or cache server.
Thanks.
BTW, you can test with this sultion: https://abp.io/support/questions/10483/v1010-Tiered-Empty-grantedPolicies-in-WebPublic-MVC-when-CmsKit-is-enabled#answer-3a1fbf3e-08f2-5b12-1295-acf09d5eb112
Thanks.
hi
This version of HttpContextAbpAccessTokenProvider will fix the problem.
Can you try to add it to your Web.Public project?
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IAbpAccessTokenProvider))]
public class MyHttpContextAbpAccessTokenProvider : HttpContextAbpAccessTokenProvider
{
public MyHttpContextAbpAccessTokenProvider(IHttpContextAccessor httpContextAccessor)
: base(httpContextAccessor)
{
}
public override async Task<string?> GetTokenAsync()
{
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext == null)
{
return null;
}
if (!httpContext.RequestServices.GetRequiredService<ICurrentUser>().IsAuthenticated)
{
var result = await httpContext.AuthenticateAsync();
if (result.Succeeded && result.Properties != null)
{
return result.Properties.GetTokenValue("access_token");
}
return null;
}
return await httpContext.GetTokenAsync("access_token");
}
}
Thanks.
Thanks. I will deep check it.
hi
Does it work if you remove CmsKit modules?
//typeof(CmsKitProPublicWebModule)
Thanks.