我有一个模型如下:
public class BaseModel
{
public DateTime? CrDate { get; set; }
[ForeignKey("CrUser")]
public ApplicationUser UserCr { get; set; }
public string CrUser { get; set; }
public DateTime? MdDate { get; set; }
[ForeignKey("MdUser")]
public ApplicationUser UserMd { get; set; }
public string MdUser { get; set; }
public bool IsDeleted { get; set; }
public void LogWhatever()
{
this.CrDate = System.DateTime.Now;
this.CrUser = ?????
}
}
如何从模型中获取已记录的用户ID以存储在CrUser中?
问候。
答案 0 :(得分:0)
Asp.net Identity会在用户登录后公开 IUser(IdentityUser)上下文。
Context.User.Identity.GetUserId()