Maybe I want to know that how to set Current User
See https://docs.abp.io/en/abp/latest/Entities#base-classes-interfaces-for-audit-properties
Originally posted by @liangshiw in https://github.com/abpframework/abp/issues/4286#issuecomment-641677741
Thanks liang, but the doc won't solve my problem.
Please read the document first : https://docs.abp.io/en/abp/latest/CurrentUser
Please read the document first : https://docs.abp.io/en/abp/latest/CurrentUser
wow ,hot and fresh!
Please read the document first : https://docs.abp.io/en/abp/latest/CurrentUser
Sorry , I still don't understand that how/where to set Current User 's properties.
Solved!
Add the code in OnApplicationInitialization method of HostModule
app.Use(async (ctx, next) =>
{
var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>();
var map = new Dictionary<string, string>()
{
{ "userId", AbpClaimTypes.UserId },
{ "role", AbpClaimTypes.Role },
{ "userNo", AbpClaimTypes.UserName },
//any other map
};
var mapClaims = currentPrincipalAccessor.Principal.Claims.Where(p => map.Keys.Contains(p.Type)).ToList();
currentPrincipalAccessor.Principal.AddIdentity(new ClaimsIdentity(mapClaims.Select(p => new Claim(map[p.Type], p.Value, p.ValueType, p.Issuer))));
await next();
});