【发布时间】:2013-09-11 20:19:15
【问题描述】:
在学习 C# 和 MVC 时,我在 VS2013 Preview 中使用股票 MVC 模板,我试图获取对当前登录的两个用户类(模板在 IdentityModel.cs 文件中创建的内容)的引用在用户中(如果适用)或来自用户 id guid。
目前我有这个(并且它有效),但它似乎有点复杂并且可能很昂贵(我不确定它是如何运作的)。
IUser iUser = await Users.Find(User.Identity.GetUserId()); //have to reference Microsoft.AspNet.Identity to access the GetUserId method
IUser iUserFromId = await Users.Find("user id guid placeholder");
User user = iUser != null ? (User)iUser : null;
有没有更清洁或更有效的方法来做到这一点?没有异步方法是否可以做到这一点?
【问题讨论】:
标签: asp.net asp.net-mvc visual-studio-2013 asp.net-mvc-5 asp.net-identity