difference between http.context.user and thread.currentprincipal and when to use them?

The first thing that the HttpApplication object does when it acquires a thread is to set the thread’s principal to the HttpContext’s principal. This syncs up the principals.

If, however, you go and set the Thread’s principal later on, the HttpApplication internally still has a different principal set for the user context. This is why you should always set it through the HttpContext.

(If you take a look in Reflector, you can see the complex code that runs when you do a “set” on HttpContext.User – it does a lot of internal stuff with IIS to properly set the principal.)

Leave a Comment