I’m reviewing an application currently experiencing problems with authentication (forms authentication is used combined with a custom way to retrieve the current user’s profile) and I’ve noticed that the user’s identity is retrieved using different methods:
- Thread.CurrentPrincipal.Identity (on some http modules)
- HttpContext.Current.User.Identity (on some http modules and also pages)
- Page.User.Identity (on pages)
Is it safe to assume that the same value will always be returned by all methods?
HttpContext.Current.User.Identity(on some http modules and also pages)Page.User.Identity(on pages)Both of them return an Instance of
IPrincipalPage.Useruses theHttpContextobject’s User property to determine where the request originatesThe best methos is
HttpContext.Current.UserThread.CurrentPrincipal.Identitywon’t show the right user if you use the Impersonationand it will give you the windows user details instead