我正在try 在将框架从.net 4.8框架更新到. net8后修复代码.我正在处理代码中的一个问题:
controller.User = new GenericPrincipal(new GenericIdentity("test"), new[] { Roles.VirtualUser });
其中控制器.用户显然是只读的.这是用户在命名空间Microsoft.AspNetCore. mva中的样子:
/// <summary>
/// Gets the <see cref="ClaimsPrincipal"/> for user associated with the executing action.
/// </summary>
public ClaimsPrincipal User => HttpContext?.User!;
我不确定是什么导致此代码被破解.我读过类似的帖子,但我不相信其中任何一个有确切的问题.我发现我可能需要一个setter方法,但不相信我可以编辑库代码.如有任何建议/提示,我们将不胜感激.谢谢!