【发布时间】:2020-05-09 00:25:00
【问题描述】:
尝试在我的 IdentityModels 文件中将 DateOfBirth 类型的声明添加到我的 userIdentity。
public class ApplicationUser : IdentityUser
{
public ICollection<Pet> Pets { get; set; }
public System.DateTime DateofBirth { get; set; }
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);
// Add custom user claims here
userIdentity.AddClaim(new Claim(ClaimTypes.DateOfBirth, this.DateofBirth));
return userIdentity;
}
}
代码CS1503的2个错误:
Argument1:无法从“字符串”转换为“System.IO.BinaryReader” Argument2:cannon 从 'System.DateTime' 转换为 'System.Security.Claims.ClaimsIdentity'
很明显我有类型错误,但我只是不知道如何将我的 DateTime 转换为字符串。
谢谢
【问题讨论】:
-
DateOfBirth.ToString("yyyy-MM-dd")
标签: c# .net asp.net-mvc asp.net-mvc-5