我今天安装了身份2.2.1。我为Role,User,Claim,UserManager,UserRole,EmailService和SmsService创建了自己的类。上述课程似乎有效。
我添加了一个名为SignInManager的新类。我似乎无法修复错误消息。我收到转换错误消息。
public class MySignInManager : SignInManager<MyUser, long>
{
public MySignInManager(MyUserManager userManager, IAuthenticationManager authenticationManager)
: base(userManager, authenticationManager)
{
}
无法将类型'System.Threading.Tasks.Task'隐式转换为'System.Threading.Tasks.Task'
public override Task<MyClaim> CreateUserIdentityAsync(MyUser user)
{
return user.GenerateUserIdentityAsync((MyUserManager)UserManager);
}
这种方法没问题
public static MySignInManager Create(IdentityFactoryOptions<MySignInManager> options, IOwinContext context)
{
return new MySignInManager(context.GetUserManager<MyUserManager>(), context.Authentication);
}
用户类如下所示:
public class MyUser : IdentityUser<long, MyLogin, MyUserRole, MyClaim>
{
public string ActivationToken { get; set; }
public string PasswordAnswer { get; set; }
public string PasswordQuestion { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(MyUserManager userManager)
{
var userIdentity = await userManager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
答案 0 :(得分:1)
该方法以Async
结束,这始终是您需要使用异步语义的良好指示:
public async override Task<MyClaim> CreateUserIdentityAsync(MyUser user)
{
return await user.GenerateUserIdentityAsync((MyUserManager)UserManager);
}
即。将async
添加到方法签名中,并await
添加结果
答案 1 :(得分:0)
我将Task MyClaim更改为Task ClaimsIdentity以解决问题。
public override Task<ClaimsIdentity> CreateUserIdentityAsync(PoseyUser user)
{
return user.GenerateUserIdentityAsync((PoseyUserManager)UserManager);
}