Thread.CurrentPrincipal.Identity vs HttpContext.User.Identity

时间:2011-07-25 00:46:18

标签: c# asp.net .net form-authentication current-principal

  

可能重复:
  difference between http.context.user and thread.currentprincipal and when to use them?

这两个在ASP.NET应用程序中有什么区别?

我知道当用户通过HttpContext.User.Identity进行身份验证时,FormsAuthentication已设置。但是Thread.CurrentPrincipal.Identity何时设定?

他们总是保持相同的价值吗?

对于无权访问HttpContext的应用程序的其他层,是否仍然适用?

2 个答案:

答案 0 :(得分:10)

HttpContext.User.Identity是您的网络应用中当前登录的用户。

Thread.CurrentPrincipal仅适用于<authentication mode = "windows"/>。通常这适用于基于Windows的应用程序(Winforms,WPF ..)

答案 1 :(得分:-3)

如果你使用HttpContext.User.Identity等于Thread.CurrentPrincipal