Handling subscription and languages in EPiServer
I recently stumbled upon a problem in EPiServer CMS 5, where no subscription e-mails were sent out - even though users had subscribed to changes for specific pages. Together with the excellent Ted Nyberg, the problem was localized and solved. Here's a post on the case plus some reference material regarding the subscription handling in EPiServer CMS 5.
First of all, the Subscription class in EPiServer is located in the EPiServer.Personalization namespace. You can find details on the subscription class in the EPiServer SDK: Subscription class
For a visitor to be able to subscribe to a page, the property EPSUBSCRIBE must be present on the page type used for the specific page.
Here's a basic example on how to subscribe a user to a page:
The SubscribeTo method automatically pics up the current user's profile and subscribes the user to the specific page.
Subscribing to a specific language version
What went wrong with the website was that there was no specification of what language version of a page a user had subscribed to.
How it came down to this one can only speculate about, but the website was migrated from EPiServer 4.11 to the latest EPiServer CMS 5 release, a huge step which might have contributed to the confusion.
To be able to narrow the problem down though, we had to take a look at two tables in the EPiServer database: aspnet_Profile and tblLanguageBranch.
- aspnet_Profile contains the profiles on the website
- tblLanguageBranch contains details on the languages available on the website
In this case, the website was a one language website.
The aspnet_Profile table
What we had to do was to first identify any user with subscription problems in the aspnet_Profile table. The easiest way to identify a specific user and find the user in the aspnet_Profile table, is to run a query on the table aspnet_Users, like this:
SELECT UserId FROM aspnet_Users WHERE UserName ='martin.soderlund';
Then you'll get the UserId, which you can use on the aspnet_Profile table, where you'll want the PropertyValuesString column’s value:
SELECT PropertyValuesString FROM aspnet_Profile WHERE UserId='[USERID]';
The PropertyValuesString column contains XML data, where the SubscriptionInfo element is of special importance. It looks like this (when subscription works as expected):
<?xml version="1.0" encoding="utf-16"?>
<SubscriptionInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Pretty much is actually obvious – information on subscribed pages for a user is stored, together with page language settings, e-mail intervals and an e-mail address to the user at the end.
What I and Ted discovered though was that the Languages element was empty - meaning no subscription e-mails were sent out for the specified language – in this case the default and only existing language.
In comes the tblLanguageBranch table, plus a language parameter for the SubscribeTo method.
The tblLanguageBranch table
To be absolutely sure about which language prefix was used on the website, we just opened the tblLanguageBranch table and realized the language id was a mis-match in regard to what was used for pages users were subscribed to.
Here's how the tblLanguageBranch table might look:
What we did, was to also add an existing language string parameter to the subscription code, in this case the fkBranchLanguageId value, "en":
Subscription.SubscribeTo(new PageReference(7), "en");
When this was done, we knew subscriptions would work. However – there was one small thing left – an EPiServer oddity.
Know how subscription works for a specific page
When you want a specific page's update to be sent out via subscription e-mail, you have to meet some requirements first:
- You'll need to tick the Mark page as changed checkbox
- The subscription scheduled job must be able to run
- You'll need to make sure the user is subscribed to the parent page
Particularly the last requirement is worth taking a note on, since a subscription to a page doesn't do what's first expected.
If you update a page ticking the Mark page as changed option, a subscription mail won't be sent out for the page's update - but for its child pages, if the Mark page as changed option is ticked.
Also, it's good to know there's a possibility to choose how often subscription e-mails should be sent, through the Interval property. Make sure you know the interval when testing!
Summary on subscriptions
To be able to send subscription e-mails, make sure the following is in place:
- You add a language parameter in the SubscribeTo method
- The same language actually exists in the tblLanguageBranch table
- You meet the requirements for page subscriptions