EPiServer: Getting a PageData Object When You Do Not Have Access to the Page

by Stephen Horsfield 31. January 2008 08:53

UPDATED: 16-MAY-2008

Overview

How can you get the PageData object for a page when the current user doesn't have access.  It took me a while to find out, but you can just read on...

Context

I have been implementing a redirect facility.  Only editors and administrators are allowed access to the page and everyone else is redirected according to a property on the page.  The ACL on the page does not give Read access to the Everyone group.  How can I get the property?

Solution

The easy solution is to use EPiServer 5.  Then you can use the GetPage method of the DataFactory class to get a page, and provide the access level:

EPiServer.Core.PageData page =
  EPiServer.DataFactory.Instance.GetPage(
    pageReference, 
    EPiServer.Security.AccessLevel.NoAccess);

UPDATED:  Thanks to Steve Celius of EPiServer for a better solution for EPiServer 4.6

Link to Steve Celius' blog: http://labs.episerver.com/en/Blogs/Steve-Celius/

In EPiServer 4.6, the EPiServer.Security.AccessLevel enumeration does not include a NoAccess member.  However, the EPiServer.Security.AccessControlList.NoAccess property is an instance of EPiServer.Security.AccessLevel and can be used directly.

THE METHOD I ORIGINALLY POSTED IS BELOW, BUT DO NOT USE IT!!!

However, I was using EPiServer 4.6 for this project, and the luxury of a NoAccess access level was not given to me!

In this case, you need to circumvent the EPiServer security model.  Of course, this probably isn't supported!  The following code does the job:

EPiServer.DataAccess.PageLoadDB pageLoadDB =
  new EPiServer.DataAccess.PageLoadDB();

EPiServer.Core.PageData page =
  pageLoadDB.Load2(pageReference);

Job done!

Versions

Metadata

Tags:

EPiServer | Security | Software Development

Comments

2/25/2008 3:01:45 PM #

Thanks for the tip. However EPDataFactory is marked deprecated in version 5. It might be better to use the code below.

EPiServer.Core.PageData page = EPiServer.DataFactory.Instance.GetPage(pageRef, EPiServer.Security.AccessLevel.NoAccess);

Håkan |

2/25/2008 5:56:51 PM #

Thanks for that.  I've updated the article.

Stephen Horsfield |

5/16/2008 9:58:20 AM #

In v4.x use EPiServer.Security.AccessControlList.NoAccess to specify that no access check should be done.

Steve Celius |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  July 2010  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar