我想让当前用户获取用户的信息,例如电子邮件.但我不能在asp.net核心中这样做.我很困惑这是我的代码.
HttpContext在控制器的构造函数中几乎为null .在每个动作中获得用户并不好.我想获得用户的信息并将其设置为ViewData;
public DashboardController()
{
var user = HttpContext.User.GetUserId();
}
Run Code Online (Sandbox Code Playgroud) 我在我的rc1项目中做过:
User.Claims.ElementAt(#).Value
Run Code Online (Sandbox Code Playgroud)
但是在我切换到rtm后它就不再起作用了.当我调试Razor视图时,对象看起来相同,但User.Claims只是空的.不知道原因是什么.