[英]asp.net identity - SetPasswordHashAsync
I'm trying to configure identity to work with custom provider. 我正在尝试配置身份以使用自定义提供程序。 So far all good, I've created UserStore
: 到目前为止一切都很好,我创建了UserStore
:
public class UserStore : IUserStore<User>, IUserPasswordStore<User>
(with all methods implemented) and UserManager: (实现所有方法)和UserManager:
public UserManager(IUserStore<User> userStore)
: base(userStore)
{ }
and User is my custom entity to hold users. 用户是我的自定义实体来容纳用户。
The problem is that in UserStore
I have the following: 问题是在UserStore
我有以下内容:
public async Task SetPasswordHashAsync(User user, string passwordHash)
From what I have understood, this is called before user is created, so all I should do here is: 根据我的理解,这是在用户创建之前调用的,所以我应该在这里做的是:
public Task SetPasswordHashAsync(User user, string passwordHash)
{
user.PasswordHash = passwordHash;
}
... but this has to return a Task and I don't see anything asynchronous to be done here. ...但是这必须返回一个Task,我在这里看不到异步。
SetPasswordHashAsync
and not just void? 为什么返回类型是SetPasswordHashAsync
Task而不仅仅是void? SetPasswordHashAsync
? 我该如何实现SetPasswordHashAsync
? I know I can do something like 我知道我可以做点什么
public async Task SetPasswordHashAsync(User user, string passwordHash)
{
user.PasswordHash = passwordHash;
await Task.FromResult(0);
}
... but isn't this synchronous? ......但这不是同步的吗? It is weird to see all other methods decorated with async
Task and use await
, and this one to return Task.FromResult()
看到用async
Task修饰的所有其他方法并使用await
,并且这个返回Task.FromResult()
是很奇怪的
Anyone? 任何人?
Tasks do not have to be asynchronous. 任务不必是异步的。 You can implement it as follows: 您可以按如下方式实现它:
public Task SetPasswordHashAsync(User user, string passwordHash)
{
user.PasswordHash = passwordHash;
return Task.FromResult(0);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.