几天前,我发现了Ben Foster撰写的关于MVC,Identity和OWIN的很好的教程.教程是here
我刚刚完成了本教程,并且发现了一个尝试覆盖功能’CreateAsync’的问题. Visual Studio不允许这样做.
这是代码:
public class AppUserClaimsIdentityFactory : ClaimsIdentityFactory<AppUser>
{
public override async Task<ClaimsIdentity> CreateAsync(
UserManager<AppUser> manager,
AppUser user,
string authenticationType)
{
var identity = await base.CreateAsync(manager, user, authenticationType);
identity.AddClaim(new Claim(ClaimTypes.Country, user.Country));
return identity;
}
}
谁知道我该如何解决这个问题?
解
感谢@ETorre,这就是最终代码!
public class AppUserClaimsIdentityFactory : ClaimsIdentityFactory<AppUser, string>
{
public async override Task<ClaimsIdentity> CreateAsync(UserManager<AppUser, string> manager,
AppUser user, string authenticationType)
{
var identity = await base.CreateAsync(manager, user, authenticationType);
identity.AddClaim(new Claim(ClaimTypes.Country, user.Country));
return identity;
}
}
解决方法:
您可以尝试查看版本吗? git上的文件使用Microsoft.AspNet.Identity.Core.dll版本1,现在是版本2.请尝试对ClaimsIdentityFactory进行内部检查