[英]GetUserAsync in Razor EF ASP.NET Core return null when already sign in?
Why does GetUserAsync return null?为什么 GetUserAsync 返回 null?
var currentUser = await _userManager.GetUserAsync(HttpContext.User);
Error:错误:
An unhandled exception occurred while processing the request.
处理请求时发生未处理的异常。 NullReferenceException: Object reference not set to an instance of an object.
NullReferenceException:Object 引用未设置为 object 的实例。 lambda_method178(Closure ) InvalidOperationException: An exception was thrown while attempting to evaluate a LINQ query parameter expression.
lambda_method178(Closure) InvalidOperationException:尝试评估 LINQ 查询参数表达式时引发异常。 See the inner exception for more information.
有关更多信息,请参阅内部异常。 To show additional information call 'DbContextOptionsBuilder.EnableSensitiveDataLogging'.
要显示附加信息,请调用“DbContextOptionsBuilder.EnableSensitiveDataLogging”。 Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.GetValue(Expression expression, out string parameterName) System.InvalidOperationException: An exception was thrown while attempting to evaluate a LINQ query parameter expression.
Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.GetValue(Expression expression, out string parameterName) System.InvalidOperationException:尝试评估 LINQ 查询参数表达式时引发异常。 See the inner exception for more information.
有关更多信息,请参阅内部异常。 To show additional information call 'DbContextOptionsBuilder.EnableSensitiveDataLogging'.
要显示附加信息,请调用“DbContextOptionsBuilder.EnableSensitiveDataLogging”。 System.NullReferenceException: Object reference not set to an instance of an object.
System.NullReferenceException:Object 引用未设置为 object 的实例。 at lambda_method178(Closure )
在 lambda_method178(闭包)
In my case I was using different branches with different DB, and claims ID were different, so when I signed in and debugged one then I went to another branched and sign in automatically, that when the error started.就我而言,我使用具有不同数据库的不同分支,并且声明 ID 不同,因此当我登录并调试一个分支时,我转到另一个分支并自动登录,即错误开始时。 So Sign out and sign in again solve the problem, because claims where different that you put in GetUserAsync().
因此,注销并再次登录可以解决问题,因为声明与您在 GetUserAsync() 中的声明不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.