Thread.CurrentPrincipal.Identity 与 HttpContext.User.Identity
这两者在 ASP.NET 应用程序中有何区别?
我知道当用户通过 FormsAuthentication 进行身份验证时会设置 HttpContext.User.Identity 。但是 Thread.CurrentPrincipal.Identity 何时设置?
它们总是具有相同的值吗?
对于无法访问 HttpContext 的应用程序的其他层来说,这仍然适用吗?
Possible Duplicate:
difference between http.context.user and thread.currentprincipal and when to use them?
What's the difference between these two in an ASP.NET application?
I know the HttpContext.User.Identity
is set when the user is authenticated through FormsAuthentication
. But when is the Thread.CurrentPrincipal.Identity
set?
Do they always hold the same value?
Does that still hold true for other layers of the application that do not have access to a HttpContext
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HttpContext.User.Identity 是 Web 应用程序中当前登录的用户。
Thread.CurrentPrincipal
仅在
时适用。通常这与基于 Windows 的应用程序(Winforms、WPF ..)一起使用HttpContext.User.Identity is the current logged in user in your web app.
Thread.CurrentPrincipal
applies only when the<authentication mode = "windows"/>
. Normally this is using with Windows based applications (Winforms,WPF..)如果您使用 HttpContext.User.Identity 等于 Thread.CurrentPrincipal
if you use the HttpContext.User.Identity equals the Thread.CurrentPrincipal