Question

I'm trying to create an application where I'm using Windows Identity and Entity Framework Code First. So I'm creating a custom class to save some data.

public class Order {
  public string Name { get; set; }
  public DateTime CreatedDate { get; set; }
  public IdentityUser User { get; set; }
}

Now I'm trying to link the user table to the order table (as generated by Entity Framework). So that I can do Order.User to get user info on the user who created the Order.

I want to create a new order using

new Order {
  Name = "Test",
  CreatedDate = new DateTime(2014, 3, 30),
  User = <What goes here?>
}

Now how to I get "IdentityUser" of the currently logged in user? Or am I going about this the wrong way?

Was it helpful?

Solution

You can get the current user from User.Identity inside of a controller, and HttpContext.Current.User.Identity from outside. Check this: ASP.NET MVC 5 - Identity. How to get current ApplicationUser

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top