可以重写ASP.. NET Identity's ApplicationUser
本文关键字:ApplicationUser Identity 重写 ASP NET | 更新日期: 2023-09-27 18:09:57
当尝试添加Override void ParseEntity并得到以下错误消息时:
项目文件行抑制状态错误CS0115 'ApplicationUser。ParseEntity(ref ApplicationUser)':找不到合适的方法覆盖…'Models'IdentityModels.cs 47 Active
我正在尝试添加:
public override void ParseEntity(ref ApplicationUser entity)
{
entity.Email = Email;
entity.UserName = Email;
entity.FirstName = FirstName;
entity.LastName = LastName;
entity.UserTypeID = UserTypeID;
entity.ModifiedDate = DateTime.Now;
entity.ModifiedBy = Id;
}
到我的IdentityModel.cs。applicationuser如下所示:
public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationUser()
{
this.Id = Guid.NewGuid().ToString();
// Add any custom User properties/code here
}
[Display(Name = "First Name")]
[Required]
public string FirstName { get; set; }
[Display(Name = "Last Name")]
[Required]
public string LastName { get; set; }
[Display(Name = "Guarantee Limit")]
public Nullable<double> GuaranteeLimit { get; set; }
[Display(Name = "User Type")]
public int UserTypeID { get; set; }
[Display(Name = "Terms And Conditions Version")]
public string TermsAndConditionsVersion { get; set; }
[Display(Name = "Last Terms And Conditions Date")]
public DateTime ? LastTermsAndConditionsDate { get; set; }
[Display(Name = "Last Login Date And Time")]
public DateTime ? LastLoginDateTime { get; set; }
[Display(Name = "Created Date")]
public DateTime CreatedDate { get; set; }
[Display(Name = "Modified Date")]
public DateTime ? ModifiedDate { get; set; }
[Display(Name = "Modified By")]
public string ModifiedBy { get; set; }
/////////////////I want to add the override here/////////////////
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager 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
return userIdentity;
}
}
我能在这里添加一个覆盖还是我错过了什么?我看了一些帖子,并尝试了使用System.Web.Mvc添加的建议,但这没有区别,相同的错误信息。
您的ApplicationUser 正在实现 IdentityUser接口。接口没有什么可重写的。您的ApplicationUser类必须从另一个类继承,该类将ParseEntity作为虚拟方法或抽象方法,以便重写。