问题描述
你好,
我一直在 UserValidator .我想为自己的项目重写它,以便能够更改错误消息.因此,我将该类复制到我的项目中.当我尝试使用它时-出现错误-'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?)
在这一行
I was looking into ASP.NET Identity source, particulary, in UserValidator. I wanted to rewrite it for my own project, to be able to change error messages. So I copy that class into my project. When I try to use it - I get an error - '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?)
at this line
var email = await Manager.GetEmailStore().GetEmailAsync(user).ConfigureAwait(false);
我的问题是-如何在AspNet.Identity框架中工作,但在我的项目中不能工作? Manager似乎没有实现IUserEmailStore
.
My question is - how can this work in AspNet.Identity framework, but not in my project? It doesn't look like that Manager is implementing IUserEmailStore
.
我测试的所有内容都是VS2013中的默认MVC模板
All I tested, was default MVC template in VS2013
推荐答案
我终于找到了答案(经过大量搜索).
I finally found the answer (after searching a lot).
如果看到UserManager的源代码,则GetEmailStore()
方法确实存在,但是是内部的.看看:
If you see the UserManager's source code, the GetEmailStore()
method does exist, but is internal. Take a look:
internal IUserEmailStore<TUser, TKey> GetEmailStore()
{
var cast = Store as IUserEmailStore<TUser, TKey>;
if (cast == null)
{
throw new NotSupportedException(Resources.StoreNotIUserEmailStore);
}
return cast;
}
因此,它仅存在于自己的Identity程序集的文件内部,这就是为什么它在那里工作而不在您的代码中出现的原因.
So, it exists only inside files of the own Identity assembly, that's why it works there and not in your code.
此外,您可以获得以下相同的结果:
Moreover, you can achieve the same result as follow:
var email = await Manager.GetEmailAsync(user.Id).ConfigureAwait(false);
这篇关于ASP.NET标识默认的ApplicationUserManager是否实现IUserEmailStore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!