c# - 试图覆盖 ClaimsIdentityFactory 上的 CreateAsync 函数

标签 c# asp.net-mvc identity owin claims

几天前,我发现了 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/

相关文章:

c# - 领域驱动设计中层与层之间的数据传输对象

c# - 如何在 C++ 中验证 Validate NCName

asp.net - 使用 Spark View 引擎在部分 View 中使用不同的 View 模型

c++ - 标准库中没有 std::identity 是有原因的吗?

sql - 使用 MS SQL Identity 是一个好的做法吗?

c# - Visual Studio 2012 "Visual C# class"模板位置

c# - 需要帮助为 UWP 创建登录系统

c# - MVC5单选按钮值错误

javascript - 如何生成完全动态的 UI? MVC 或 WebForms

identity - dbt - 如何创建表创建自动增量列