0
私はClaimsAbpSessionを拡張し、アングルアプリとサーバーの間でリクエストに送信される新しいプロパティを作成する必要があります。Extend ClaimsAbpSession
実際、私はこれらの新しいプロパティをクレームを使用して保存しました。しかし、ユーザーがページを更新すると、クレームの値が失われます。
私はClaimsAbpSessionを拡張し、アングルアプリとサーバーの間でリクエストに送信される新しいプロパティを作成する必要があります。Extend ClaimsAbpSession
実際、私はこれらの新しいプロパティをクレームを使用して保存しました。しかし、ユーザーがページを更新すると、クレームの値が失われます。
MyAppSession.cs
//Define your own session and add your custom field to it
//Then, you can inject MyAppSession and use it's new property in your project.
public class MyAppSession : ClaimsAbpSession, ITransientDependency
{
public MyAppSession(
IPrincipalAccessor principalAccessor,
IMultiTenancyConfig multiTenancy,
ITenantResolver tenantResolver,
IAmbientScopeProvider<SessionOverride> sessionOverrideScopeProvider) :
base(principalAccessor, multiTenancy, tenantResolver, sessionOverrideScopeProvider)
{
}
public string UserEmail
{
get
{
var userEmailClaim = PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == "Application_UserEmail");
if (string.IsNullOrEmpty(userEmailClaim?.Value))
{
return null;
}
return userEmailClaim.Value;
}
}
}
UserClaimsPrincipalFactory.cs
//Override CreateAsync method to add your custom claim
public override async Task<ClaimsPrincipal> CreateAsync(User user)
{
var claim = await base.CreateAsync(user);
claim.Identities.First().AddClaim(new Claim("Application_UserEmail", user.EmailAddress));
return claim;
}
おかげアルパース。セッションに追加された値はトークンに更新されますか? –
カスタムフィールドはトークンに影響しません。 –