Ok I have made a lot of progress. I can now add a new page with a new instance of the HTML module. However, I cannot seem to get the HTML module to show on the page if the user is not logged in. The strange thing is it seems that I have the correct permissions. In order to get the module to show to unregistered users I have to log in, and then make a change (update) the text in the HTML module, then it will show for all.
Here is my code - I would really appreciate if someone could run their eyes over this and let me know what I am doing wrong:
[
WebMethod(Description = "Creates a new page")]public int CreatePage(string pageName, string content, string title, string lang)TabController controller;TabInfo newTab;int newTabId;out controller, out newTab, out newTabId);ModuleInfo modInfo;int newModuleID;out modInfo, out newModuleID);return newTabId; private static void AddHTMLModule(string content, string title, DotNetNuke.Entities.Modules.ModuleInfo modInfo, int newModuleID)////////////////////////////
//// HTML Module ////
////////////////////////////
DotNetNuke.Modules.HTML.
DotNetNuke.Modules.HTML.
htmlinfo.ModuleID = newModuleID;
htmlinfo.Approved =
htmlinfo.Comment =
htmlinfo.IsPublished =
htmlinfo.Content = content;
htmlinfo.IsActive =
htmlinfo.PortalID = 0;
htmlinfo.IsPublished =
htmlinfo.StateID = 1;
modInfo.ModuleTitle = title;
modInfo.InheritViewPermissions =
modInfo.ModuleTitle = title;
HtmlTextInfo htmlinfo = new DotNetNuke.Modules.HTML.HtmlTextInfo();HtmlTextController htmlcont = new DotNetNuke.Modules.HTML.HtmlTextController();true;"Published via WebService";true;true;true;false;//htmlinfo.WorkflowID = 1;
//htmlinfo.WorkflowName = "Direct Publish";
//htmlinfo.Approved = true;
htmlcont.UpdateWorkflowID(modInfo.ModuleID, 0, 1);
htmlcont.UpdateHtmlText(htmlinfo, maxVersion);
htmlcont.UpdateMaximumVersionHistory(0, htmlcont.GetMaximumVersionHistory(0));
htmlcont.UpdateWorkflowID(newModuleID, 0, htmlcont.GetWorkflowID(newModuleID, 0));
}
{
int maxVersion = htmlcont.GetMaximumVersionHistory(0);private static void SetModulePermissions(int newModuleID)/////////////////////////////
//// Module Permissions ////
/////////////////////////////
DotNetNuke.Security.Permissions.
DotNetNuke.Security.Permissions.
DotNetNuke.Security.Permissions.
modPerm.AllowAccess =
modPerm.ModuleID = newModuleID;
modPerm.PermissionID = 1;
modPerm.AllowAccess =
modPerm.RoleID = -1;
modPermCon.AddModulePermission(modPerm);
modPerm2.AllowAccess =
modPerm2.ModuleID = newModuleID;
modPerm2.PermissionID = 2;
modPerm2.AllowAccess =
modPerm2.RoleID = 0;
modPermCon.AddModulePermission(modPerm2);
}
{
ModulePermissionInfo modPerm = new DotNetNuke.Security.Permissions.ModulePermissionInfo();ModulePermissionInfo modPerm2 = new DotNetNuke.Security.Permissions.ModulePermissionInfo();ModulePermissionController modPermCon = new DotNetNuke.Security.Permissions.ModulePermissionController();true;true;true;true;private static void AddNewModule(string title, int newTabId, out DotNetNuke.Entities.Modules.ModuleInfo modInfo, out int newModuleID)///Add module to newTab
modInfo =
DotNetNuke.Entities.Modules.
modInfo.DisplayTitle =
modInfo = mc.GetModuleByDefinition(0,
new DotNetNuke.Entities.Modules.ModuleInfo();ModuleController mc = new DotNetNuke.Entities.Modules.ModuleController();true;"Text/HTML");//modInfo.Header = "header string"; //not needed
//modInfo.IsDefaultModule = true;//do we need this?
modInfo.PaneName =
modInfo.TabID = newTabId;
modInfo.ModuleTitle = title;
"ContentPane";//modInfo.DesktopModuleID = 68; //HTML text module
modInfo.ModuleID = -1;
//modInfo.ModuleID = 390;
//modInfo.PortalID = 0;
modInfo.EndDate = System.
modInfo.InheritViewPermissions =
DateTime.Now.AddYears(10);false; //TODO: this is not working as expected.
modInfo.IsDefaultModule =
modInfo.ModuleOrder = 1;
modInfo.AllTabs =
modInfo.DisplayPrint =
newModuleID = mc.AddModule(modInfo);
false;false;false;//add module to the page
}
{
private static void ClearCaches(DotNetNuke.Entities.Tabs.TabController controller, DotNetNuke.Entities.Tabs.TabInfo newTab)// clear cache
controller.ClearCache(0);
}
{
DataCache.ClearModuleCache(newTab.TabID);DataCache.ClearTabsCache(0);DataCache.ClearCache();DataCache.ClearModulePermissionsCache(newTab.TabID);DataCache.ClearTabPermissionsCache(0);DataCache.ClearDesktopModulePermissionsCache();DataCache.ClearPortalCache(0, true);private static void AddPagePermissions(int newTabId)///////////////////
//Tab Permissions.
///////////////////
DotNetNuke.Security.Permissions.
DotNetNuke.Security.Permissions.
DotNetNuke.Security.Permissions.
DotNetNuke.Security.Permissions.
tabPInfo.AllowAccess =
tabPInfo.PermissionID = 1;
tabPInfo.PermissionID = 4;
tabPInfo.RoleID = 0;
tabPInfo2.AllowAccess =
tabPInfo2.PermissionID = 1;
tabPInfo2.PermissionID = 3;
tabPInfo2.RoleID = -1;
tabPInfo.TabID = newTabId;
tabPInfo2.TabID = newTabId;
tp.Add(tabPInfo,
tp.Add(tabPInfo2,
tpc.AddTabPermission(tabPInfo);
tpc.AddTabPermission(tabPInfo2);
}
{
TabPermissionCollection tp = new DotNetNuke.Security.Permissions.TabPermissionCollection();TabPermissionInfo tabPInfo = new DotNetNuke.Security.Permissions.TabPermissionInfo();TabPermissionInfo tabPInfo2 = new DotNetNuke.Security.Permissions.TabPermissionInfo();TabPermissionController tpc = new DotNetNuke.Security.Permissions.TabPermissionController();true;true;true);true);private static void AddPage(string pageName, out DotNetNuke.Entities.Tabs.TabController controller, out DotNetNuke.Entities.Tabs.TabInfo newTab, out int newTabId)////////////////////////////////////
///// Add Page (Tab) //////
////////////////////////////////////
controller =
newTab =
new DotNetNuke.Entities.Tabs.TabController();new DotNetNuke.Entities.Tabs.TabInfo();//newTab.LocalizedTabName = lang; //read only.
controller.ClearCache(0);
newTab.PortalID = 0;
newTab.TabName = pageName;
newTab.Title = pageName;
newTab.Description = pageName;
newTab.KeyWords = pageName;
newTab.IsDeleted =
newTab.IsSuperTab =
newTab.IsVisible =
newTab.DisableLink =
newTab.IconFile =
newTab.ParentId = 39;
false;false;true;false;"";//TODO: this is hardcoded. Is there a better way?
newTab.Url =
"";//TODO: if the URL is to have a language value, need to figure out how to correctly use this property.
newTabId = controller.AddTab(newTab);
//add new page.
}
{
DotNetNuke.Entities.Tabs.
DotNetNuke.Entities.Tabs.
AddPage(pageName,
AddPagePermissions(newTabId);
ClearCaches(controller, newTab);
DotNetNuke.Entities.Modules.
AddNewModule(title, newTabId,
ClearCaches(controller, newTab);
SetModulePermissions(newModuleID);
ClearCaches(controller, newTab);
AddHTMLModule(content, title, modInfo, newModuleID);
ClearCaches(controller, newTab);
}
{