可能重複:
difference between http.context.user and thread.currentprincipal and when to use them?Thread.CurrentPrincipal.Identity VS HttpContext.User.Identity
是什麼在ASP.NET應用程序中這兩者之間的區別?
我知道當用戶通過FormsAuthentication
認證的HttpContext.User.Identity
設置。但是什麼時候設置了Thread.CurrentPrincipal.Identity
?
難道他們始終保持相同的值?
這是否仍然適用於那些沒有訪問HttpContext
應用程序的其他層?
'Thread.CurrentPrincipal'仍然有效使用'模式= 「形式」 '... – bevacqua
@Nico:但它不會給你當前的登錄用戶。它會給你的Windows用戶的細節。所以,在這種情況下,Thread.CurrentPrincipal沒有多大意義。 – CharithJ
在Forms Authentication中,Thread.CurrentPrincipal可能會與HttpContext.User.Identity不一致。請參閱從[Hanselman的(http://www.hanselman.com/blog/SystemThreadingThreadCurrentPrincipalVsSystemWebHttpContextCurrentUserOrWhyFormsAuthenticationCanBeSubtle.aspx)這個老博客。另請參閱此更新[stackoverflow](http://stackoverflow.com/a/16693746) – subsci