问题
I have a model as below :
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 = ?????
}
}
How can i get the logged userID from model to store in CrUser ?
regards.
回答1:
Asp.net Identity expose IUser(IdentityUser) Context, once user logged in.
Context.User.Identity.GetUserId()
来源:https://stackoverflow.com/questions/23288879/how-to-get-identity-user-data-from-asp-net-mvc-model