EDIT: The problem doesn't always follow this pattern. It seems that sometimes it only works once for every restart of the IIS-application.
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
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="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Test of FindPagesWithCriteria</title> </head> <body> <h1>All article pages</h1> <table> <thead> <tr> <th>Id</th> <th>Name</th> <th>Url</th> </tr> </thead> <tbody> <% foreach (var articlePage in articlePages) { var friendlyUrl = FriendlyLinkUrl(articlePage); %> <tr> <td><%: articlePage.ContentLink.ID %></td> <td><%: articlePage.Name %></td> <td><a href="<%: friendlyUrl%>"><%: friendlyUrl%></a></td> </tr> <%}%> </tbody> </table> </body> </html> <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; } </script>
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
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)
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)?
I see. I tried but with no success. I even removed the FilterForVisitor. This is really weird :/
That is strange..
Sorry for going on with all questions.
This is independent on pagetypeid?
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.
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
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.....
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?
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.
Hi Andreas,
Thanks for the quick response. Yes we too did a workaround as we werent able to find a solution either..
I'm using FindPagesWithCriteria with this code ->
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!