是否有一种内置方法可以将持久模型数据与 MVC4 中经过身份验证的用户相关联,或者您是否应该提供自己的实现?
我读过的 MSDN 教程没有建议如何做到这一点,但我看到了一个可以存储WebSecurity.CurrentUserId
属性。例如,允许用户上传照片的网站模型:
public class Photo
{
public int Id { get; set; }
public int UserID { get; set; } // Controller sets WebSecurity.CurrentUserId?
public DateTime Created { get; set; }
...
}
还是有"MVC 方式"?
你能不能不要使用这样的东西:
public class Photo
{
public int Id { get; set; }
public int UserID { get; set; }
public DateTime Created { get; set; }
public UserProfile user {get;set;}
...
}
public class UserProfile
{
public int UserID { get; set; }
}