如何从Asp.net mvc Model获取身份用户数据

时间:2014-04-25 09:12:48

标签: asp.net-mvc identity

我有一个模型如下:

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中?

问候。

1 个答案:

答案 0 :(得分:0)

Asp.net Identity会在用户登录后公开 IUser(IdentityUser)上下文。

Context.User.Identity.GetUserId()