Wednesday, 3 November 2010

Role Redirect

Recently I needed to redirect all users with certain roles as soon as they landed on a specific page - in other words, if a user in X role landed on this page, they would be redirected immedately; everyone else (from all other roles) would see the page normally.

The targeted content part built-in to Netcommunity allows you to target roles specifically with different content, but it doesn't allow you to perform redirects. So I built a custom part to do the job instead. In this post I'll explain what it does - in the next post, I will upload the code so you can see it all.

Role Redirect

The first problem was that Netcommunity doesn't appear to expose the list of roles via the API. It allows you to check whether a user is in a particular role (API.Users.CurrentUser.IsInRole), but that's only useful if you already know the name of the role.

To get around this, my custom part hooks straight into the BBNC database - the Roles table is very simple. When you edit the part, it fetches the list of Roles from the database - you can then select one (or more ) roles that you want to redirect when they land on a page with the part on it.

You then choose the page you want to redirect them to by using the PageLink server control - I don't think I've posted about server controls before, so I'll explain it in more detail in the next post. They are built-in bits of functionality that Blackbaud kindly provide as part of the API - there's more information on them here. They allow you to use some of the built-in Netcommunity parts, like the query picker, HTML editor, link picker, and more.

Once you've picked your page and picked the roles you want to redirect - that's it. You save, and put the part on a page.

The next post will be quite long as this is a more complicated custom part than I've posted before - it'll be up this week.

0 comments:

Post a Comment