Can you share the HTTP response detail (include header and body)?
Try
public static class RefreshRolesMiddlewareExtension
{
public static IApplicationBuilder UseRefreshRolesMiddleware(this IApplicationBuilder app)
{
return app.Use(async (ctx, next) =>
{
var currentUser = ctx.RequestServices.GetRequiredService<ICurrentUser>();
if (!currentUser.IsAuthenticated)
{
await next();
return;
}
var userManager = ctx.RequestServices.GetRequiredService<IdentityUserManager>();
var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>();
var user = await userManager.GetByIdAsync(currentUser.GetId());
var roles= await userManager.GetRolesAsync(user);
var claims = currentPrincipalAccessor.Principal.Claims.ToList();
claims.RemoveAll(x => x.Type == AbpClaimTypes.Role);
claims.AddRange(roles.Select(x=> new Claim(AbpClaimTypes.Role, x)));
using (currentPrincipalAccessor.Change(claims))
{
await next();
}
});
}
}
Hi,
I have reproduced the problem, thank you, we will fix it. see https://github.com/abpframework/abp/pull/11006
PS: your ticket refunded.
For now, you can try:
[ExposeServices(
typeof(ICachedApplicationConfigurationClient),
typeof(IAsyncInitialize)
)]
public class MyMvcCachedApplicationConfigurationClient : ICachedApplicationConfigurationClient, ITransientDependency
{
protected IHttpContextAccessor HttpContextAccessor { get; }
protected AbpApplicationConfigurationClientProxy ApplicationConfigurationAppService { get; }
protected ICurrentUser CurrentUser { get; }
protected IDistributedCache<ApplicationConfigurationDto> Cache { get; }
public MyMvcCachedApplicationConfigurationClient(
IDistributedCache<ApplicationConfigurationDto> cache,
AbpApplicationConfigurationClientProxy applicationConfigurationAppService,
ICurrentUser currentUser,
IHttpContextAccessor httpContextAccessor)
{
ApplicationConfigurationAppService = applicationConfigurationAppService;
CurrentUser = currentUser;
HttpContextAccessor = httpContextAccessor;
Cache = cache;
}
public async Task InitializeAsync()
{
await GetAsync();
}
public async Task<ApplicationConfigurationDto> GetAsync()
{
var cacheKey = CreateCacheKey();
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
configuration = await Cache.GetOrAddAsync(
cacheKey,
async () => await ApplicationConfigurationAppService.GetAsync(),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(300) //TODO: Should be configurable.
}
);
if (httpContext != null)
{
httpContext.Items[cacheKey] = configuration;
}
return configuration;
}
public ApplicationConfigurationDto Get()
{
var cacheKey = CreateCacheKey();
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is ApplicationConfigurationDto configuration)
{
return configuration;
}
return AsyncHelper.RunSync(GetAsync);
}
protected virtual string CreateCacheKey()
{
var userKey = CurrentUser.Id?.ToString("N") ?? "Anonymous";
return $"ApplicationConfiguration_{userKey}_{CultureInfo.CurrentUICulture.Name}";
}
}
Hi,
Yes, IList<IFormFile> and IList<IRemoteStreamContent> both work.
Is there any benefit for me using IList<IRemoteStreamContent> here?
IRemoteStreamContent work with dynamic/static proxy system.
Hi,
Thanks for the demo, I will check it.
Hi,
I will check it , thanks.
Hi,
I have to try testing with a new startup template, but can't reproduce the problem, can you provide full steps? thanks.