2014-10-08 54 views
3

几天前,我发现了Ben Foster关于MVC,Identity和OWIN的非常好的教程。本教程是here尝试覆盖ClaimsIdentityFactory上的CreateAsync函数

我刚刚完成教程,并且发现尝试覆盖函数“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; 
    } 
} 
+2

您可以将代码附加为文本代替。没有人想调试代码的图片。 – Matthew 2014-10-08 14:04:51

+1

谢谢,我刚刚将代码附加为文本。 @Matthew – 2014-10-08 14:13:39

回答

3

你可以试试看看版本?在git上的文件使用Microsoft.AspNet.Identity.Core.dll版本1,现在它是vervion 2.尝试内部的ClaimsIdentityFactory

+0

谢谢@ETorre,我会试试! – 2014-10-08 14:11:55

+0

这工作正常!再次感谢@ETorre! – 2014-12-22 23:53:03