【发布时间】:2015-12-29 02:41:08
【问题描述】:
我有这门课:
public class AppUser : IdentityUser
{
public virtual Organization Organization { get; set; }
}
当我在控制器操作中获取用户时:
public async Task<IActionResult> MyAction()
{
var user = await GetCurrentUserAsync();
if (user != null)
{
// **user.Organization is null here**
}
return View();
}
...
private async Task<AppUser> GetCurrentUserAsync()
{
return await _userManager.FindByIdAsync(HttpContext.User.GetUserId());
}
我可以获取所有用户属性,但不能获取我添加的自定义属性。我检查了数据库,并在 aspnetusers db 中为此用户设置了“组织”。
有什么想法吗?
【问题讨论】:
-
你试过this answer吗?
标签: asp.net-core-mvc entity-framework-core