Assuming a fairly general use case in an ASP.NET Web Forms application, where should I be retrieving my principal + identity?
I'm aware that there are generally two ways to go about it:
HttpContext.Current.User
Thread.CurrentPrincipal
I'm speculating that using HttpContext
will run the risk of a current context not existing (i.e. HttpContext.Current == null
) on some edge cases, but I more often see code that use this instead of Thread.CurrentPrincipal
(which I assume is safer, as it should always exist?).
Why is this? What implications am I getting myself into if I pick one or the other?