Do you have SaveAction set to Publish in your save page code?
- Kjetil Simensen
I am having the exact same problem.
I've written code to add a page to Episerver:
DataFactory.Instance.Save(newClonedPage, EPiServer.DataAccess.SaveAction.Publish, AccessLevel.NoAccess);
When my scheduled job starts to add more pages it checks to see if this page has already been published - but it doesnt find this page.
If I am logged onto the Episerver interface, then the page can be found, but if I am not logged in then I cant find the page.
I hope someone can provide a solution for this problem!
A related question would be: What user is used when the Job scheduler executes jobs?
When do you do the search, directly after the page is created? If so it could be a good idea to set the start publish slightly in the past:
The reason for that is that EPiServer might not see the page as published if the search comes direclty after the page has been created, and thus filtering the page if the user is anonymous.
It could also be an access rights problem, if the currently logged lacks read access to the page it will not be returned from the search.
"A related question would be: What user is used when the Job scheduler executes jobs?"
When the job is run by the scheduler, it will be run as an anonymous user. If you select "start manualy" from the UI it will be run with as the user that started the job.
Per GunsarfsEPiServer CMS development team
The page is almost a day old when I search for it through the job that I've scheduled... I think the problem is that with the scheduled job the anonymous user is not allowed to find that page - even through code - so the episerver search in my Job does not function properly?
How can I find these pages through code as an anonymous user? Currently I am having the problem of duplicate pages since I cannot verify through code that a page already exists.
EPiServer.DataAbstraction.SearchPages fbn = new EPiServer.DataAbstraction.SearchPages(); PageReference infrPage = fbn.FindByName(infshort.InfringeNoticeN);
but I've also tried to find it by Criteria... same problem!
Two ways to find pages in a scheduled job that anonymous users lacks access to.
1. To impersonate a user for the job. I think I saw a blog post somewhere describing how.
2. Use the method EPiServer.DataFactory.FindAllPagesWithCriteria. It's a rather new method, think it was added to EPiServer CMS R2 perhaps SP1. It was made to support just this issue. It will return all hits, leaving the filtering up to you.
Noticed you were using the FindByName method. Since FindAllPagesWithCriteria is more generic you'll have to create a criteria to match PageName yourself.
Edit: Found the blog post I mentioned, http://antecknat.se/blog/2009/03/04/scheduled-tasks-tips/.