Custom Navigation based on a Custom Security
We've implemented a custom membership provider and a custom table for permissions etc based on our own user and role base.
Since the out of the box navigation control is based on Roles in Sitefinity we can't use it. We need to get to a level deeper in our own security implementation. Do I use a Kendo UI Web menu control and PageManager? Is there an example someone can point me to or put in here on how to do this?
Thanks,
David
Hello David,
One way of implementing the navigation is to bind a hierarchical data control to our SitefinitySiteMapDataSource declarative control, i.e. it would provide the datasource automatically to the control which will use it. You can then subscribe to ItemDataBound event of that control and implement some custom logic for modifying the item when it's bound to the control, since this event will fire for every item that gets bound. You can then filter each item depending on your criteria and choose whether to show it or not.
Example:
<
asp:Repeater
ID
=
"Repeater1"
runat
=
"server"
DataSourceID
=
"SiteMapDataSource"
>
</
asp:Repeater
>
<
asp:SiteMapDataSource
runat
=
"server"
ID
=
"SiteMapDataSource"
StartingNodeOffset
=
"0"
ShowStartingNode
=
"false"
/>
protected
void
Page_Load(
object
sender, EventArgs e)
Repeater1.ItemDataBound +=
new
RepeaterItemEventHandler(Repeater1_ItemDataBound);
Repeater1.DataBind();
void
Repeater1_ItemDataBound(
object
sender, RepeaterItemEventArgs e)
if
(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
var data = e.Item.DataItem
as
PageSiteNode;
if
(data !=
null
)
if
(data.ShowInNavigation ==
false
)
e.Item.Visible =
false
;
var source = App.WorkWith().Pages()
.ThatArePublished()
.Where(p => p.ShowInNavigation ==
true
&& p.IsBackend ==
false
&& p.Id != SiteInitializer.BackendRootNodeId)
.Get()
.ToList();
MyNavControl.DataSource = source;
MyNavControl.DataTextField =
"Title"
;
MyNavControl.DataFieldID =
"Id"
;
MyNavControl.DataFieldParentID =
"ParentId"
;
MyNavControl.DataBind();
This seems good.
I was having trouble figuring out how to take the Fluent Source you defined in this example and use it in the widget template I've defined along with the asp:SiteMapDataSource. Is there another way?
I started looking at implementing a CustomSiteMapProvider in the place of the Sitefinity one so I can define what my site map is based on our custom security... but I immediately received an error.
A required control was not found in the template for "~/SfCtrlPresentation/OpenAccessDataProvider,1d5cbcbced74667ba552ff01008b77a8.ascx". The control must be assignable from type "Telerik.Sitefinity.Web.UI.NavigationControls.SitefinitySiteMapDataSource" and must have ID "dataSource".
I guess Sitefinity doesn't want me to do this?
Hi David,
I suppose you are trying to change the navigation default template. In this case the template is searched in a virtual directory, which path is shown in the error message. You can easily fix this by creating an actual folder SfCtrlPresentation in the root of your SitefinityWebApp. The template should be placed in this folder and with this exact name, following the convention <provider>,<id>.ascx or in this case - OpenAccessDataProvider,1d5cbcbced74667ba552ff01008b77a8.ascx . Keep in mind that by switching the default template you should have an exact structure and controls, as in the current scenario a SitefinitySiteMapDataSource control with an ID: dataSource. If you create an entirely new control you will not have this limitation. You can also take a look at this forum post.
Regards,
Nikola Zagorchev
Telerik
No I'm simply trying to get a new Widget Template defined and use it in a Page.
That's the error I'm getting. I didn't make it the default. I can switch it back to another template for navigation and it's fine. Just doesn't work with the one I defined.
Hi David,
You can also achieve your scenario creating your own SitefinitySiteMapDataSource inheriting from Telerik.Sitefinity.Web.UI.NavigationControls.SitefinitySiteMapDataSource. You can then override the CheckNode method and return bool value whether the node should be present in the navigation or not, depending on your custom logic and scenario.
You can then replace the SitefinitySiteMapDataSource control in the beginning of one of the default templates with the one you have implemented.
Regards,
Nikola Zagorchev
Telerik