的UserManager不包含CreateIdentity一个定义 [英] UserManager does not contain a definition for CreateIdentity

查看:217
本文介绍了的UserManager不包含CreateIdentity一个定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图迁移该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一个定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆