Hi khaled,
if we don't get valid page entity even if the pageId is greater that -1 , simple Re-Assign pageId to -1
This is already what happens in this code:
if(pageId > -1)
{
pageSettings = new PageSettings(siteSettings.SiteId, pageId);
}
else
if a non existent page id (or one that may exist in a different site) is passed in, then the pageSettings object is created by this constructor with an id of -1 and it ignores the passed in id, so it is in new page creation mode already and the user must have permissions to create new pages or he will not be allowed. Since there are some places further down in the code where we check pageId again, I will change it like this to force the parameter back to -1:
if(pageId > -1)
{
pageSettings = new PageSettings(siteSettings.SiteId, pageId);
if (pageSettings.PageId == -1) { pageId = -1; }
}
if(pageId == -1)
{
pageSettings = new PageSettings();
....
Best,
Joe