你好,
我一直在UserValidator中研究ASP.NET Identity源,尤其是。我想为自己的项目重写它,以便能够更改错误消息。所以我将该类复制到我的项目中。当我尝试使用它时-'Microsoft.AspNet.Identity.UserManager<TUser,TKey>' does not contain a definition for 'GetEmailStore' and no extension method 'GetEmailStore' accepting a first argument of type 'Microsoft.AspNet.Identity.UserManager<TUser,TKey>' could be found (are you missing a using directive or an assembly reference?)
在此行出现错误
var email = await Manager.GetEmailStore().GetEmailAsync(user).ConfigureAwait(false);
我的问题是-如何在AspNet.Identity框架中工作,但不能在我的项目中工作?管理器似乎没有实现IUserEmailStore
。
我测试的是VS2013中的默认MVC模板
我终于找到了答案(经过大量搜索)。
如果您看到UserManager的源代码,则该GetEmailStore()
方法确实存在,但是是内部的。看一看:
internal IUserEmailStore<TUser, TKey> GetEmailStore()
{
var cast = Store as IUserEmailStore<TUser, TKey>;
if (cast == null)
{
throw new NotSupportedException(Resources.StoreNotIUserEmailStore);
}
return cast;
}
因此,它仅存在于自己的Identity程序集的文件内部,这就是为什么它在此处而不是在代码中起作用的原因。
此外,您可以获得以下相同的结果:
var email = await Manager.GetEmailAsync(user.Id).ConfigureAwait(false);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句