Setting permissions on custom Orchard menu links

Often times your navigation does not point to a content item in Orchard and you still need to set permissions on that link. For example, a "Sign In" link or a "Logout Link". Because you can't associate permissions to specific Users/Accounts pages in the Administration UI, you need to be able to do this via the Content Permissions and Custom Link content type. Although you can inject the User shape into your Layout file where you want it, sometimes you need it to live inside the primary or utility navigation and it is tough to style this when it does not render inside the navigation shape. Follow the steps below to integrate login/logout into your navigation.

Navigation Configuration

First, start off by adding a Custom Link item in your navigation for "Member Sign In" and "Logout". 

Next, you would set those URL's to the following locations.

/Users/Account/Logon and /Users/Account/Logoff

Once you save this, you will see these links appear on your site and they take you to the appropriate actions for Orchard. They are however both shown when a user is authenticated and anonymous to the site.

Custom Link Content Type Modification

Next you should go and modify the Custom Link content type. You will need to enable the Content Permissions Module from the Modules menu before doing this as well.

Once in the Custom Link content type modification page, add the Content Permissions part to the type via the Admin UI. You should also set the following permissions by default. This is because login and logoff links realy only deal with Anonymous and Authenticated roles.

Configure Your Menu Items to use Permissions

Lastly, go back to the navigation menu and modify your "Member Sign In" and "Logoff" links to utilize the content permissions part. 

For the "Member Sign In" link, set the following permissions :

For the "Logout" link, set the following permissions :

As you can see, we are basically just saying that if you are logged in you get the logout link, if you are not you get the login link. Save your items and test out your new functionality! Hope this helps you customize your Orchard navigation by permissions/roles when you need login/logout links encapsulated in it.

About the Author:

Arra Derderian serves as the President and as a Lead Technical Architect for Cloud Construct. As a founder at Cloud Construct, Arra is involved in all levels of the business from new project engagements, project planning, and development.

He also serves as the founder of the Boston Orchard CMS User Group and is a member of the Windows Azure Insiders group.

Arra graduated from Northeastern University School with a Bachelor of Science degree in Computer Science.

Our website uses cookies to distinguish you from other users of our website. This helps us to provide you with a good experience when you browse our website, and also allows us to improve our site. By continuing you accept the use of these cookies.

× dismiss