Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

FindPagesWithCriteria only find pages once


I'm using FindPagesWithCriteria with this code ->

var contentTypeId = _contentTypeRepository.Load().ID.ToString();

            var criterias = new PropertyCriteriaCollection
                new PropertyCriteria()
                    Name = "PageTypeID",
                    Condition = CompareCondition.Equal,
                    Required = true,
                    Type = PropertyDataType.PageType,
                    Value = contentTypeId

            var pages = _pageCriteriaService.FindPagesWithCriteria(parentLink.ToPageReference(), criterias);

This works 100% fine on local machine but not in our test server. Sure, some Id's are different but that doesn't matter since we don't hardcode anything.

So what's wrong on the test server... Well I only find pages on the first request to this method after any publish on the site. No errors, it just returns 0 pages. I can't see any logic in this. The server has memory and everything it needs. As far as I know FindPagesWithCriteria doesn't cache anything itself and the database doesn't change.

I'm using version 7.

Anyone know what to do? Thanks!

Mar 13, 2015 16:36

EDIT: The problem doesn't always follow this pattern. It seems that sometimes it only works once for every restart of the IIS-application.

Mar 14, 2015 20:33

I would start by doing profiling on the database to see what is going on there.

I would also creata a simple aspx-page without backend code (all code in the aspx-page) so it would be easy to try, and to know that the site only doing that

Edited, Mar 16, 2015 7:41

To make searching for error more simple, create a aspx-page in the root and then remove the backend files (cs and design).

I have made a simple (remember that this is a quick test so it might not be the optimal code for everything) page that works on a alloy site.

<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="EPiServer" %>
<%@ Import Namespace="EPiServer.Core" %>
<%@ Import Namespace="EPiServer.DataAbstraction" %>
<%@ Import Namespace="EPiServer.Filters" %>
<%@ Import Namespace="EPiServer.ServiceLocation" %>
<%@ Import Namespace="EPiServer.Web.Routing" %>
<%@ Import Namespace="FindPagesTest.Models.Pages" %>

<!DOCTYPE html>

    var articlePages = GetAllArticles().ToList();
<html xmlns="">
<head runat="server">
    <title>Test of FindPagesWithCriteria</title>
    <h1>All article pages</h1>
        <% foreach (var articlePage in articlePages)
               var friendlyUrl = FriendlyLinkUrl(articlePage);
                <td><%: articlePage.ContentLink.ID %></td>
                <td><%: articlePage.Name %></td>
                <td><a href="<%: friendlyUrl%>"><%: friendlyUrl%></a></td>

<script runat="server">

    private static IEnumerable<PageData> GetAllArticles()
        var result = new List<PageData>();
        var articlePageId = ServiceLocator.Current.GetInstance<IContentTypeRepository>().Load<ArticlePage>().ID;
        result.AddRange(FilterForVisitor.Filter(GetAllPagesOfCertainPageType(articlePageId, ContentReference.StartPage)));

        return result;

    public static PageDataCollection GetAllPagesOfCertainPageType(int pageTypeDefinitionId, PageReference root)
        var propertyCriteriaCollection = new PropertyCriteriaCollection
            new PropertyCriteria
                Condition = CompareCondition.Equal,
                Name = "PageTypeID",
                Type = PropertyDataType.PageType,
                Value = pageTypeDefinitionId.ToString(CultureInfo.InvariantCulture),
                Required = true

        var pagesOfCorrectType = DataFactory.Instance.FindPagesWithCriteria(root, propertyCriteriaCollection);

        return pagesOfCorrectType;

    public static string FriendlyLinkUrl(PageData pageData)
        var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
        var url = urlResolver.GetUrl(pageData.ContentLink);
        return !string.IsNullOrWhiteSpace(url) ? url.ToLowerInvariant() : string.Empty;

Mar 16, 2015 8:54

Hi Henrik and thanks for replying.

We did a SQL profiling that only made us more confused. As I wrote in the question my understanding of FindPagesByCriteria is that it's always fetching from the database. This is confirmed by looking in the profiler. This SQL query is always run everytime we do the FindPagesWithCriteria.

exec netPropertySearchValueMeta @PageID=1636,@PropertyName=N'PageTypeID',@LanguageBranch=NULL,@Equals=1,@NotEquals=default,@GreaterThan=default,@LessThan=default,@Boolean=default,@Number=default,@FloatNumber=default,@PageType=37,@PageLink=default,@Date=default

The purpose of this procedure is to return PageIds. It always returns the correct ids, regardless of the end result. In that case it's the method itself that do something after it has gotten the result from the database.

EDIT: We have a webapi that do this so we didn't try your aspx-example, it's no extra code behind it at the moment so it's clean

Edited, Mar 16, 2015 10:37

Do you get the same error for all page types or just for this?

Do you get the error when run a page like the one I gave example on?
(The good thing with that one is that you can add it to whatever enviroment and run it without deploying anything)

Mar 16, 2015 11:14

What do you mean by "error"? There are no exceptions thrown...

Mar 16, 2015 12:29

Sorry, I meen more behavor, meaning that you do not get any result back more than the first time after a IIS-reset.

Could you try with the example I gave earlier (but change the pagetype to the one you have problem with)?

Mar 16, 2015 12:49

I see. I tried but with no success. I even removed the FilterForVisitor. This is really weird :/

Mar 16, 2015 14:45

That is strange..
Sorry for going on with all questions.

This is independent on pagetypeid?

Mar 16, 2015 15:08

No it's good that you keep asking question, even though it's not THE solution it makes you think in different paths.

It looks like it is only for page types of the type Container pages right now (no controller/view connected to it).

Mayby it's a problem with page types being changed during publishes, but no such pattern is seen.

Mar 16, 2015 15:16

I have never tried to use it with that kind of content.

See if you can recreate it in a alloy site and report it as a bug.

I will try it but does not have the time to do it right now

Mar 16, 2015 15:38

After removing filterforvisitor (that will remove all containerpage-content) I am not able to reproduced it for the Alloy project, but I am on 8.0 with that, so it might been fixed now, maby.....

Mar 16, 2015 19:28

Hi  Andreas Johansson ,

We have exactly the same issue like you have.Code is below for your perusal.

var serviceLocationHelper = ServiceLocator.Current.GetInstance<ServiceLocationHelper>();

var criterias = new PropertyCriteriaCollection();


var criteria = new PropertyCriteria();

criteria.Condition = CompareCondition.Equal;

criteria.Name = "PageTypeID";

criteria.Type = PropertyDataType.PageType;

criteria.Value = serviceLocationHelper.ContentTypeRepository().Load("BunkerFuelPriceUpdatePage").ID.ToString();

criteria.Required = true;


var priceUpdatePages = serviceLocationHelper.PageCriteriaQueryService().FindPagesWithCriteria(ContentReference.StartPage, criterias);


It works fine on local machine and staging machine, but not on Production server.

Can you please if you have found a solution?

Dec 08, 2015 8:11

Hi Sylvia,

We gave up and took a workaround actually. Don't remember what we did instead but we didn't find a solution for this.

Dec 08, 2015 8:15

Hi Andreas,

Thanks for the quick response. Yes we too did a workaround as we werent able to find a solution either..

Dec 08, 2015 8:26
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.