Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive

Adding a new option to the menu in my desk

Modified: 2010/02/26 09:30 by vanthoog - Categorized as: Kentico
This article shows how to add a new menu option to the (left) menu in the “my desk” section of CMSDesk.

Note: All code in this article has been written for testing and prototyping purposes only. For use in a proper application this code needs to be optimized and refactored.

All menus in CMSDesk are hardcoded in the code of CMSDesk. The good news is that all code of CMSDesk is available and can therefore be modified. In this article we will focus on the (left) menu of “my desk”, but many aspects also apply to other menus in CMSDesk. You just have to locate the proper source files containing a specific menu.

In this article we will add a menu option called “AVHTest01”.

To add a new menu option to the (left) menu of “my desk” the following main steps have to be performed: 1. Add a new aspx-file containing the actual code which will be executed when someone selects the new menu option. 2. Add the new menu option.

All code of “my desk” can be found in “/CMSDesk/MyDesk”. We will create our new page in a new folder called AVH and the page is called AVHTest01.aspx. This is a normal aspx-file, which is not using a master page. It can contain anything you want. The only thing special is that it must inherit from CmsDeskPage:

public partial class CMSDesk_MyDesk_AVH_AVHTest01 : CMSDeskPage

Now we are going to add the menu option. The (left) menu of “my desk” can be found in “/CMSDesk/MyDesk/leftmenu.aspx”. When you open this file and go to the code-behind you will see that the Page_Load contains many occurrences of the following piece of code:

newNode = new TreeNode();
newNode.Text = "" + ResHelper.GetString("MyDesk.WaitingForApprovalMenu") + "";
newNode.NavigateUrl = "#";
newNode.ImageUrl = imagesUrl + "WaitingForApproval.gif";
rootNode.ChildNodes.Add(newNode);

The only thing we have to do is make a copy of this piece of code and change it to fit our needs:

newNode = new TreeNode();
newNode.Text = "" + "AVHTest01" + "";
newNode.NavigateUrl = "#";
newNode.ImageUrl = imagesUrl + "password.gif";
rootNode.ChildNodes.Add(newNode);

Notice how we have only changed the content of the property “Text”. The property “ImageUrl” should also be changed but for simplicity we have just used the password icon.

And that’s all. The menu will now show our new menu option:
Menu in

Menu in "my desk"


This menu option will be available to all users in all sites. If this is not what you want you can add appropriate if-statements to limit access. For example, the following if-statement will only make the menu option available in the site “avh1website”:

if (CMS.CMSHelper.CMSContext.CurrentSiteName == "avh1website")
{
    newNode = new TreeNode();
    newNode.Text = "" + "AVHTest01" + "";
    newNode.NavigateUrl = "#";
    newNode.ImageUrl = imagesUrl + "password.gif";
    rootNode.ChildNodes.Add(newNode);
}

Often it makes more sense to limit access bases on the role of a user. This can be achieved by using CMSContext.CurrentUser.IsInRole. This has one drawback; global administrators will not have access. So in this case it is advisable to also add a check on CMSContext.CurrentUser.IsGlobalAdministrator:

if (CMS.CMSHelper.CMSContext.CurrentUser.IsGlobalAdministrator
    || CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("AVHPRManagers", "avh1website")
    )
{
    newNode = new TreeNode();
    newNode.Text = "" + "AVHTest01" + "";
    newNode.NavigateUrl = "#";
    newNode.ImageUrl = imagesUrl + "password.gif";
    rootNode.ChildNodes.Add(newNode);
}

A final word about security. Because a menu option points to a aspx-file, “bad guys” might try to access the page directly by copying the url into the address bar of their browser. So if you add any security checks to the menu, make you also add them to the Page_Load of the page itself. By the way, the inheritance of CmsDeskPage already checks that the user is logged in and authorized to access CmsDesk.

 © Evident Interactive BV