gpt4 book ai didi

asp.net - User.Identity 与 Thread.CurrentPrincipal.Identity?

转载 作者:行者123 更新时间:2023-12-01 12:30:13 25 4
gpt4 key购买 nike

有一些页面试图对此进行解释,但我没有找到最近的页面,所以请允许我再问一次。

asp.net MVC 5 中,User.IdentityThread.CurrentPrincipal.Identity 有什么区别?

我试着打印它的名字并声明出来,它们对我来说看起来是一样的,也许我漏掉了什么。

最佳答案

我相信您已经阅读过:Thread.CurrentPrincipal vs Current.User , 没有必要重新解释同一件事。

我想您的问题的答案取决于您正在开发的应用程序。如果它是 Web 应用程序(例如 ASP.NET MVC),那么你应该喜欢 User.Identity因为User.Identity专为网络应用程序而设计。

通常它们之间没有区别,因为 ASP.NET 确保它们同步..(除非你按照 Scott 的说明更改了它们)

有些情况下您不想(也无权访问)System.Web , 所以你必须使用 Thread.CurrentPrincipal.Identity .

另请注意上面的 Scott 博客。如果您要更改其中一个,请确保它们同步。

关于asp.net - User.Identity 与 Thread.CurrentPrincipal.Identity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34940862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com