Thorkil Holm-Jacobsen
Thorkil Holm-Jacobsen

Reputation: 7676

Visitor groups using Viewed Pages criterion not working

I am working on a page which should use visitor groups to personalize its contents. However, I cannot seem to get the Visited Page criterion to match.

I assume that the Visited Page criteron uses the class EPiServer.Personalization.VisitorGroups.Criteria.ViewedPagesCriterion, which stores the viewed pages in the HttpContext session with the key EPiServer:ViewedPages. Unfortunately, the session key doesn't seem to be added at all when I enter the specified pages.

Has anyone got any idea why it isn't working?


EDIT: I have now tried to implement the Criterion myself, bascially using the decompiled code from EPiServer.Personalization.VisitorGroups.Criteria.ViewedPagesCriterion. It turns out that the criterion subscribes to a VisitedPage event which is supposedly raised when a page is visited. By debugging, I have determined that the event subscription is successful, but the event handler is never called. This means that, for some reason, EPiServer does not raise the event.

I tried to subscribe to the StartRequest event instead, and in this case the handler is called. This begs the question: Why is the VisitedPage event not raised when visiting pages?

Upvotes: 1

Views: 708

Answers (1)

Thorkil Holm-Jacobsen
Thorkil Holm-Jacobsen

Reputation: 7676

The VisitedPage event is fired only when a page is shown through a controller which has the ViewedPageCriterionAttribute. The base controller EPiServer.Web.Mvc.PageController<T> provided by EPiServer has this attribute, so the it works when controllers inherit from this controller.

If you do not wish to use PageController, the attribute has to be used on your custom controller:

[ViewedPageCriterion]
public class MyController<T> : Controller<T> where T : IDefaultModel
{
    // controller implementation
}

Upvotes: 1

Related Questions