可能重复:
difference between http.context.user and thread.currentprincipal and when to use them?
这两个在ASP.NET应用程序中有什么区别?
我知道当用户通过HttpContext.User.Identity
进行身份验证时,FormsAuthentication
已设置。但是Thread.CurrentPrincipal.Identity
何时设定?
他们总是保持相同的价值吗?
对于无权访问HttpContext
的应用程序的其他层,是否仍然适用?
答案 0 :(得分:10)
HttpContext.User.Identity是您的网络应用中当前登录的用户。
Thread.CurrentPrincipal
仅适用于<authentication mode = "windows"/>
。通常这适用于基于Windows的应用程序(Winforms,WPF ..)
答案 1 :(得分:-3)
如果你使用HttpContext.User.Identity等于Thread.CurrentPrincipal