How to get Identity User Data from Asp.net mvc Model

孤街浪徒 提交于 2019-12-25 08:24:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!