小编ori*_*uig的帖子

尝试重写 ClaimsIdentityFactory 上的 CreateAsync 函数

几天前,我发现 Ben Foster 写的一篇关于 MVC、Identity 和 OWIN 的非常好的教程。教程在这里

我刚刚完成本教程,在尝试重写函数“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;
    }
}
Run Code Online (Sandbox Code Playgroud)

有人知道我该如何解决这个问题吗?

解决方案

感谢@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;
    } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc identity claims owin

5
推荐指数
1
解决办法
3683
查看次数

标签 统计

asp.net-mvc ×1

c# ×1

claims ×1

identity ×1

owin ×1