【发布时间】:2019-12-18 18:20:31
【问题描述】:
var userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
var user = await userManager.FindByNameAsync(context.UserName);
我在context.UserName 中获得了值,并且数据库中存在相同的用户名。但是FindByNameAsync() 函数有时会在第一次调用时返回 null。
如果我再次调用相同的函数,它会按预期提供输出。当我在下面的代码中调用它时。
if(user == null) {
var user = await userManager.FindByNameAsync(context.UserName);
}
谁能帮我解决这个问题?
非常感谢。
【问题讨论】:
-
context.UserName值是如何给出的? -
OAuthGrantResourceOwnerCredentialsContext
-
第一次通话时,
context.UserName是否有价值?在分配OAuth...CredentialContext.UserName? -
是的,它确实有价值。
-
这一行
var user = await userManager.FindByNameAsync(context.UserName)只能在您传递的用户名不在您的数据库中时给您 null
标签: c# asp.net asp.net-mvc asp.net-mvc-4 asp.net-web-api