C# Thread.CurrentPrincipal.Identity.Id与this.User.Identity.GetuserId()的比较

C# Thread.CurrentPrincipal.Identity.Id与this.User.Identity.GetuserId()的比较,c#,multithreading,C#,Multithreading,我在API控制器中找到了遗留代码 var user = await _userService.FindAsync(x => x.UserName == Thread.CurrentPrincipal.Identity.Name); if (user == null) return NotFound(); 我不知道什么时候应该使用Thread.CurrentPrincipal.Identity.Name而不是简单的this.User.Identity.GetUserId() 有什么不同吗?

我在API控制器中找到了遗留代码

var user = await _userService.FindAsync(x => x.UserName == Thread.CurrentPrincipal.Identity.Name);
if (user == null) return NotFound();
我不知道什么时候应该使用
Thread.CurrentPrincipal.Identity.Name
而不是简单的
this.User.Identity.GetUserId()

有什么不同吗?

我想这就是你想要的。一个是运行线程的操作系统帐户。另一个是web用户标识。