Using a Page - Content Area with blocks, if a block is not published but dragged into content area and the page publshed it was still showing all block content in my Repeater control.
I have been able to get around this by using the AccessLevel Read to work as its status but is there a better way or is this a bug?
IEnumerable<MyCustomBlock> myitems = CurrentPage.ContentAreaName.Contents .Where(a => a.QueryDistinctAccess(AccessLevel.Read)) .Select(b => b as MyCustomBlock)
rptRepeater.DataSource = myitems;rptRepeater.DataBind();
Try using FilteredContents instead of Contents to get the blocks that the current user should see when viewing a page. This handles filtering of access rights, deleted items, non published items and in the future even items that have been personalized and doesn't match the current user.
Thanks I have tried using FilteredContents but it still gives me the same results, I am not logged into to episerver as I am testing via anouther browser and cleared full session and cache, still seems to be a bug unless I need to specifiy more on the filteredcontents.
Will leave with AccessLevel.Read check for now as this gives me the results I need and see if I can find any more on this issue.
I have reported a bug that the FilteredContents property does not do filtering for access rights etc. Until this has been fixed you can use the FilterContentsForVisitor filter. Something like this:
var content = someContentArea.FilteredContents;new FilterContentForVisitor().Filter(content);return content;
Content is edited
the problem still if the block is Expired the FilteredContents dosn't work. Somebody know how to filtred on the blocks not expired?
If you are using EPiSerer 7.5 you should be able to use the FilteredItems property.
Nope. I can't get FilteredItems to work in EPiServer 7.5 either. Blocks that are scheduled for publish at a later date still shows up in FilteredItems.
Update to my previous post. It seems that the filtering works fine if the block has never been published (and then using FilteredContents is sufficient. But if the block once has been published and you set a future publish date, the filtering does not work. None of the following filter methods work if the block has once been published:
var items = CurrentBlock.Offers.FilteredItems; var offers = items.Select(i => contentRepository.Get<BlockData>(i.ContentLink) as IContent).ToList(); new FilterPublished().Filter(offers);
offers = offers.FilterForVisitors().ToList(); OffersListView.DataSource = offers; OffersListView.DataBind();
Hoping this helps someoneAlex
I cannot reproduce what you are saying with the latest packages. I have four items, one of them is a published block that I have changed the publish date till next year. When I call the FilteredItems method I only get three items but the Items property returns all four.
© Episerver 2016 |
About Episerver World