What's the difference between HttpContext.Current.User and Thread.CurrentPrincipal in asp.net?

后端 未结 2 1710
一个人的身影
一个人的身影 2020-12-05 16:03

Well, I think the title is clear enough.

2条回答
  •  一向
    一向 (楼主)
    2020-12-05 17:03

    Another big difference is that your code doesn't always have access to the HttpContext. (For example if you have all of your BL in an assembly that may or may not be used from a web application) While they two user accounts can be different, if you use the Thread.CurrentPrincipal then your code will always be able to get at that user object no matter where you are in your code.

提交回复
热议问题