我刚刚切换到使用Identity Framework的新2.0版本。在1.0中,我可以通过使用获取用户对象manager.FindByIdAsync(User.Identity.GetUserId())
。该GetUserId()
方法似乎在2.0中不存在。
现在,我能确定的是使用manager.FindByEmailAsync(User.Identity.Name)
哪些表引用了用户表中的用户名字段。在我的应用程序中,此设置与电子邮件字段相同。
当有人需要更新电子邮件时,我可以看到这会导致问题。是否可以通过Identity 2.0 Framework中不变的值(例如id字段)来获取当前登录的用户对象?
GetUserId()
是的扩展方法,IIdentity
位于中Microsoft.AspNet.Identity.IdentityExtensions
。确保使用添加了名称空间using Microsoft.AspNet.Identity;
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句