在ASP.NET Identity 2.0中获取当前用户标识
我刚刚切换到使用身份框架的新的2.0版本。 在1.0中,我可以通过使用manager.FindByIdAsync(User.Identity.GetUserId())来获取用户对象。  GetUserId()方法似乎不存在于2.0中。 
 现在我只能find引用users表中用户manager.FindByEmailAsync(User.Identity.Name) 。 在我的应用程序中,它设置为与电子邮件字段相同。 
当有人需要更新他们的电子邮件时,我可以看到这引起问题。 有没有一种方法来获取当前login的用户对象基于身份2.0框架中不变的值(如id字段) ?
  GetUserId()是GetUserId()的扩展方法,它在Microsoft.AspNet.Identity.IdentityExtensions 。 确保你已经using Microsoft.AspNet.Identity;添加了命名空间using Microsoft.AspNet.Identity;  。 
 为了得到Asp.net Identity 2.0中的CurrentUserId,首先导入Microsoft.AspNet.Identity : 
C#:
 using Microsoft.AspNet.Identity; 
VB.NET:
 Imports Microsoft.AspNet.Identity 
 然后调用User.Identity.GetUserId()到处都是你想要的: 
 strCurrentUserId = User.Identity.GetUserId() 
 此方法返回当前用户标识作为数据库中用户标识的定义数据types(缺省值为String )。 
万一你像我一样,用户实体的Id字段是一个Int或除string以外的东西,
 using Microsoft.AspNet.Identity; int userId = User.Identity.GetUserId<int>(); 
会做的伎俩