几天前,我发现了 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 进行内初始化
关于c# - 试图覆盖 ClaimsIdentityFactory 上的 CreateAsync 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26258812/