问题描述
我试图迁移该code到ASP.NET V5:
I'm trying to migrate this code to ASP.NET V5:
public ClaimsIdentity GenerateUserIdentity(UserManager<User> manager, string authenticationType)
{
var userIdentity = manager.CreateIdentity(this, authenticationType);
...
我得到的误差的UserManager&lt;使用者&GT;不包含CreateIdentity定义
任何想法如何解决这个问题?
Any ideas how to fix it?
推荐答案
要创建一个 ClaimsPrincipal
从 TUSER
对象,你可以导入 IUserClaimsPrincipalFactory&LT; TUSER&GT;
在自己的code和调用 CreateAsync
:
To create a ClaimsPrincipal
from a TUser
object, you can import IUserClaimsPrincipalFactory<TUser>
in your own code and call CreateAsync
:
var principal = await factory.CreateAsync(user);
另外,您也可以使用的UserManager&LT; TUSER&GT; .GetClaimsAsync
- 这就是 UserClaimsPrincipalFactory&LT; TUSER&GT;
用途幕后 - 并创建一个 ClaimsIdentity
自己:
Alternatively, you can also use UserManager<TUser>.GetClaimsAsync
- which is what UserClaimsPrincipalFactory<TUser>
uses behind the scenes - and create a ClaimsIdentity
yourself:
var identity = new ClaimsIdentity(await manager.GetClaimsAsync(user), authenticationType);
这篇关于的UserManager不包含CreateIdentity一个定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!