获取当前用户ID在ASP.NET 2.0身份 [英] Get current user id in ASP.NET Identity 2.0
问题描述
我只是切换到使用新的2.0版本的身份框架。在1.0,我可以用得到的用户对象 manager.FindByIdAsync(User.Identity.GetUserId())
。在 GetUserId()
方法似乎并不在2.0〜存在。
I just switched over to using the new 2.0 version of the Identity Framework. In 1.0 I could get a user object by using manager.FindByIdAsync(User.Identity.GetUserId())
. The GetUserId()
method does not seem to exists in 2.0.
现在我可以找出是使用 manager.FindByEmailAsync(User.Identity.Name)
它引用在用户表中的用户名字段。在我的应用中,则设置为一样的电子邮件领域。
Now all I can figure out is to use manager.FindByEmailAsync(User.Identity.Name)
which references the username field in the users table. In my application this is set to the same as the email field.
我可以看到这个导致问题的道路,当有人需要更新他们的电子邮件。有没有办法让登录的用户基于对象的关闭不变的值,当前的(如id字段)的在Identity 2.0框架?
I can see this causing issues down the road when someone needs to update their email. Is there a way to get the current logged in user object based off an unchanging value (such as the id field) in the Identity 2.0 Framework?
推荐答案
GetUserId()
是一个扩展方法的IIdentity
键,它是在 Microsoft.AspNet.Identity.IdentityExtensions
。请确保您已使用Microsoft.AspNet.Identity添加了命名空间;
GetUserId()
is an extension method on IIdentity
and it is in Microsoft.AspNet.Identity.IdentityExtensions
. Make sure you have added the namespace with using Microsoft.AspNet.Identity;
.
这篇关于获取当前用户ID在ASP.NET 2.0身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!