API Questions on Kentico API.
Version 6.x > API > Setting a Document Alias using API on CMSMessages/SiteOffline.aspx View modes: 
User avatar
Member
Member
christine.kemme-salespad - 10/22/2012 2:43:50 PM
   
Setting a Document Alias using API on CMSMessages/SiteOffline.aspx
I am trying to create a document alias for the CMSMessages/SiteOffline.aspx page through the API by using this method
    private bool CreateDocumentAlias()
{
// Get "Home" document
CMS.TreeEngine.TreeNode document = CMS.CMSHelper.TreeHelper.GetDocument(CMSContext.CurrentSiteName, "/CMSMessages/SiteOffline", CultureHelper.GetPreferredCulture(), true, "CMS.MenuItem", false);

if (document != null)
{
// Create new document alias object
CMS.TreeEngine.DocumentAliasInfo newAlias = new CMS.TreeEngine.DocumentAliasInfo();

// Set the properties
newAlias.AliasURLPath = "/SiteOffline";
newAlias.AliasNodeID = document.NodeID;
newAlias.AliasSiteID = CMSContext.CurrentSiteID;

// Save the document alias
CMS.TreeEngine.DocumentAliasInfoProvider.SetDocumentAliasInfo(newAlias, CMSContext.CurrentSiteName);

return true;
}

The problem is that I have no idea what the class name would be (the 'CMS.MenuItem' part). I've tried getting to the information by looking at the CMS.CMSHelper.CMSContext.CurrentPageInfo.ClassName.ToString(); but it always returns that the CurrentPageInfo is null.

Any suggestions on how to do this would be greatly appreciated!

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 10/24/2012 10:48:54 PM
   
RE:Setting a Document Alias using API on CMSMessages/SiteOffline.aspx
Hi,

Where do you call that code from? Is it run on some specific application lifecycle phase (event) or somewhere outside?
If I'm correctly assuming, you can use other filtering criteria, as the ClassName parameter set to empty (null) will search among all the document types - then, the path would be most significant.
Any additional information about your aim could help maybe.

Regards,
Zdenek

User avatar
Member
Member
davids-kentico - 10/25/2012 2:35:05 AM
   
RE:Setting a Document Alias using API on CMSMessages/SiteOffline.aspx
You can't do it llike that. SiteOffline.aspx is an actual physical page, while document aliases can only be assigned to documents stored in the content repository (i.e., the content tree in CMS Desk).

You may be able to solve this by creating a new ASPX page template (Site Manager -> Development -> Page templates) and assign the physical page as the template file. Then create a page in the content tree based on the template and modify that page using the API.

Or you can catch the request to the URL you want and redirect it to the SiteOffline page. Use CMSRequest handlers for that. Some info about customizing event handlers is here:
http://devnet.kentico.com/docs/devguide/index.html?event_handlers_overview.htm

Hope this helps.

User avatar
Member
Member
christine.kemme-salespad - 10/25/2012 9:16:11 AM
   
RE:Setting a Document Alias using API on CMSMessages/SiteOffline.aspx
I was afraid that was the problem.

I am displaying this page when the site is taken offline via the CMS Desk (Site Manager > Sites > Offline Mode) but since the path is ~/CMSMessages/SiteOffline, a user can get to the CMSMessages directory which I do not like.

Was hoping that by adding an alias, I could change the page url to just ~/SiteOffline and hide the CMSMessages from any users.

Would the CMSRequest handlers help with this?
I'm not very familiar with the Kentico CMS stuff yet...

User avatar
Member
Member
davids-kentico - 10/25/2012 10:23:16 AM
   
RE:Setting a Document Alias using API on CMSMessages/SiteOffline.aspx
Alright, the simplest (though not very elegant) solution is to just copy the page over to the root of the project. Then you don't have to worry about the CMSMessages part. However, you'll need to add "/SiteOffline.aspx" to Settings -> URLs and SEO -> Excluded URLs.

If you don't want users to access the CMSMessages folder, I would advise you turn off directory browsing for that folder.

Plus, when the site is off-line and someone requests the CMSMessages folder, the system redirects them to the SiteOffline page anyway. Still, you should really turn off directory browing for the folder, or any other system folder for that matter.

User avatar
Member
Member
christine.kemme-salespad - 10/25/2012 10:35:32 AM
   
RE:Setting a Document Alias using API on CMSMessages/SiteOffline.aspx
Thank you very much for the help! I now have it working and the directories hidden.