0

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 Answer 1

0

Asp.net Identity expose IUser(IdentityUser) Context, once user logged in.

Context.User.Identity.GetUserId()
Sign up to request clarification or add additional context in comments.

3 Comments

Should i only, write Context.User.Identity.GetUserId() ?? It is not working, since not found the context ?
HttpContext.Current.User.Identity.GetUserId(); is the right answer ? That is solve my question but is it good approach ?
are you able to access HttpContext in your model ? and this is exact way/approach how usercontext should be available to the application. let me know i'll have a look then.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.