ASP.NET Identity 默认的 ApplicationUserManager 是否实现了 IUserEmailStore?
ASP.NET Identity Is default ApplicationUserManager implementing IUserEmailStore?
你好,
我正在调查 ASP.NET 身份来源,特别是 UserValidator。我想为我自己的项目重写它,以便能够更改错误消息。所以我将 class 复制到我的项目中。当我尝试使用它时 - 我收到错误 - '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);
你好,
我正在调查 ASP.NET 身份来源,特别是 UserValidator。我想为我自己的项目重写它,以便能够更改错误消息。所以我将 class 复制到我的项目中。当我尝试使用它时 - 我收到错误 - '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);