Hello,
I'm trying to protect all the pages of an Area, using this code:
PageCollection areaPages = Dynamicweb.Content.Page.GetPagesByAreaID(areaId);
foreach (var areaPage in areaPages)
{
if (!string.IsNullOrEmpty(passwordTextBox.Text))
{
areaPage.Password = passwordTextBox.Text;
areaPage.Protect = true;
}
else
{
areaPage.Password = null;
areaPage.Protect = false;
}
areaPage.Save(false);
}
But it only takes effect on the frontend after doing an application pool recycle. Am I missing something?
My code also stores the area password on a table in the database and applies to each page on Page.Saved subscriber.
Dynamicweb.Notifications.Standard.Page.PageNotificationArgs pna = (Dynamicweb.Notifications.Standard.Page.PageNotificationArgs)args;
DatabaseDataContext dataContext = DatabaseDataContext.GetNewContext();
string newPassword = dataContext.AreaCustomFields.FirstOrDefault(p => p.AreaId == pna.Target.AreaID).Password;
if (pna.Target.Password != newPassword && !(pna.Target.Password == null && newPassword == string.Empty))
{
if (!string.IsNullOrEmpty(newPassword))
{
pna.Target.Password = newPassword;
pna.Target.Protect = true;
}
else
{
pna.Target.Password = null;
pna.Target.Protect = false;
}
pna.Target.Save(false);
}
Thanks,
Diogo