public IUser GetAuthenticatedUser()
{
if (HttpContext.Current == null || HttpContext.Current.User == null)
return null;
// attempts to get the user from the UserPart data store if it wasn't previously set.
if (_authenticatedUser == null)
_authenticatedUser = _membershipService.Value.GetUser(HttpContext.Current.User.Identity.Name);
// if the user wasn't previously set, and doesn't exist in the UserPart data store, then the
// current active directory user is returned instead.
if (_authenticatedUser == null)
return new ActiveDirectoryUser();
// return previously set user, or the user fetched from the data store.
return _authenticatedUser;
}
}