using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
///
/// Use members of this class instead of HttpContext.Current.Profile to access
/// profile information of the current user, or of a user account that is being impersonated.
///
namespace MB.eQuest
{
public class AppProfile
{
const string PROFILE_SESSION_KEY = "objMembershipUserProfile";
public AppProfile()
{
//
// TODO: Add constructor logic here
//
}
///
/// Gets the profile of the current user.
/// Since this may not always be the logged in user, query the ProfileCommon object
/// for the AppMembership.User user, which will always be:
/// a) the logged in user
/// b) the user currently being impersonated, regardless of who is logged in.
///
public static ProfileCommon UserProfile
{
get
{
ProfileCommon p = new ProfileCommon();
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.Session[PROFILE_SESSION_KEY] == null)
HttpContext.Current.Session[PROFILE_SESSION_KEY] = p.GetProfile(AppMembership.User.UserName);
return (ProfileCommon)HttpContext.Current.Session[PROFILE_SESSION_KEY];
}
else
{
//Get user's anonymous profile
return p.GetProfile(HttpContext.Current.Profile.UserName);
}
}
}
///
/// Gets the profile of the specified user.
///
public static ProfileCommon GetUserProfile(string UserName)
{
ProfileCommon p = new ProfileCommon();
return p.GetProfile(UserName);
}
///
/// Delete the cached ProfileCommon object.
/// This will cause it to be retrieved and cached again when the UserProfile property is accessed again.
///
public static void Clear()
{
HttpContext.Current.Session[PROFILE_SESSION_KEY] = null;
}
}
}