3
.NET .NET RC2に.NET 4.6バージョンを移植しており、.NET Core RC2でのフォローを行う方法が不思議です。.NET Core RC2のサインインに関するクレーム
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
userIdentity.AddClaim(new Claim("FullName", string.Format("{0} {1}", this.Firstname, this.Lastname)));
userIdentity.AddClaim(new Claim("Organization", this.Organization.Name));
userIdentity.AddClaim(new Claim("Role", manager.GetRoles(this.Id).FirstOrDefault()));
userIdentity.AddClaim(new Claim("ProfileImage", this.ProfileImageUrl));
// Add custom user claims here
return userIdentity;
}
、次にアイデンティティの拡張方法。私User.Identity.ProfileImg();
などを使用した結果を与える
public static class IdentityExtensions
{
public static string FullName(this IIdentity identity)
{
var claim = ((ClaimsIdentity)identity).FindFirst("FullName");
// Test for null to avoid issues during local testing
return (claim != null) ? claim.Value : string.Empty;
}
public static string Organization(this IIdentity identity)
{
var claim = ((ClaimsIdentity)identity).FindFirst("Organization");
// Test for null to avoid issues during local testing
return (claim != null) ? claim.Value : string.Empty;
}
public static string Role(this IIdentity identity)
{
var claim = ((ClaimsIdentity)identity).FindFirst("Role");
// Test for null to avoid issues during local testing
return (claim != null) ? claim.Value : string.Empty;
}
public static string ProfileImage(this IIdentity identity)
{
var claim = ((ClaimsIdentity)identity).FindFirst("ProfileImage");
// Test for null to avoid issues during local testing
return (claim != null) ? claim.Value : string.Empty;
}
}
..あなたたちは待っせるため申し訳ありません
のために私の見解では、このようなものです。 – conterio
私は自分のコンピュータに戻ったときに私がそれをどのように解決したかについて答えを提供します。 @JeremyConterio – Rovdjuret
それは素晴らしいだろう – conterio