1. Theme
Theme is for the look and feel of web pages. Themes can use CSS files also. Just put the CSS file under specific theme folder, the page will use it.
File structure:
[Web App Root]\App_Themes\Blue\blue.shin
Then you can appay this skin in several way:
//In Single Page
//In Page_PreInit Event
void Page_PreInit(object sender, System.EventArgs e)
{ this.Theme = "Blue";}
2. Personalization
Let's save the Theme setting in Profile. In web.config file, add
〈 providers〉
〈 add name="myProfileProvider" type="Corp.Framework.Shared.Security.myProfileProvider, Corp.Framework.Shared" connectionStringName="ConnID"/〉
〈 /providers〉
〈 properties〉
〈 add name="Theme" defaultValue="Blue"/〉
〈 /properties〉
〈 /profile〉
//In Page_PreInit Event, you load user's setting from Profile
void Page_PreInit(object sender, System.EventArgs e)
{
this.Theme = Profile.Theme;
//Page.Theme = (string)HttpContext.Current.Profile["Theme"];
}
3. myProfileProvider
myProfileProvider inherits from the SettingsProvider abstract class, which inherits from the ProviderBase abstract class.
class myProfileProvider : ProfileProvider
{
#region Private Member
private string _applicationName;
#endregion // Private Member
#region Constructor
///
/// Default Constructor
///
public myProfileProvider()
: base()
{
}
#endregion // Constructor
#region Initialize
///
/// Initialize the Profile Provider Class
///
/// Provider name
/// NameValueCollection containing the provider configuration settings
public override void Initialize(string name, NameValueCollection config)
{
}
#endregion //Initialize
#region Get Application Name
public override string ApplicationName
{
get { return _applicationName; }
set { _applicationName = value; }
}
#endregion
#region GetPropertyValues
///
/// Get Property Values
///
/// Context
/// Collection of Property Value
public override SettingsPropertyValueCollection
GetPropertyValues(SettingsContext context,
SettingsPropertyCollection ppc)
{
// In Web form, user login by their email, here username pass the email
string email = (string)context["UserName"];
bool isAuthenticated = (bool)context["IsAuthenticated"];
SettingsPropertyValueCollection svc =
new SettingsPropertyValueCollection();
foreach (SettingsProperty prop in ppc)
{
SettingsPropertyValue pv = new SettingsPropertyValue(prop);
switch (prop.Name)
{
case "Theme":
pv.PropertyValue = GetTheme(email, isAuthenticated, (string)prop.DefaultValue);
break;
default:
throw new ProviderException("Unsupported property.");
}
svc.Add(pv);
}
UpdateActivityDates(email, isAuthenticated, true);
return svc;
}
#endregion //GetPropertyValues
#region SetPropertyValues
///
/// Set Perperty Values
///
/// Context
/// Collection of Property value
public override void SetPropertyValues(SettingsContext context,
SettingsPropertyValueCollection ppvc)
{
…
}
#endregion //SetPropertyValues
#region UpdateActivityDates
///
/// when profile properties are accessed by the
/// GetPropertyValues and SetPropertyValues methods.
/// Passing true as the activityOnly parameter will update
/// only the LastActivityDate.
///
/// Current user's email
/// is Authenticated
/// Activity
private void UpdateActivityDates(string email, bool isAuthenticated, bool activityOnly)
{
DateTime activityDate = DateTime.Now;
}
#endregion //UpdateActivityDates
#region GetTheme
///
/// Retrieves theme from the database during the call to GetPropertyValues.
///
/// Current user's email
/// is Authenticated
///
private string GetTheme(string email, bool isAuthenticated, string defaultTheme)
{
if (!isAuthenticated)
{
return defaultTheme;
}
if (null == email)
throw new ArgumentNullException("email");
// check if username is empty
if (email.Length == 0)
throw new ArgumentException("Argument is empty", "username");
try
{
// create the object manager
IUsersManager usersManager = ManagerFactory
// Validate
IUsers user = usersManager.RetrieveByemail(email);
if (user.IsEmpty)
return defaultTheme;
if (string.IsNullOrEmpty(user.theme))
return defaultTheme;
else
return user.theme;
}
catch
{
throw;
}
}
#endregion
}