I'm trying to create an unsubscribe feature via email link from the subscription emails that are sent out. The unsubscribe link contains the GUID of the Membership User and this is used to retrieve the EPiServer user profile:
MembershipUser member = Membership.GetUser(Guid.Parse(userGuidStr));
EPiServerProfile user = EPiServerProfile.Get(member.UserName);
Then all PageReferences in user.SubscriptionInfo.ListSubscriptions are passed to user.SubscriptionInfo.UnSubscribe and finally user.Save is called.
However, when the EPiServer.Web.WebControls.SubscriptionList is still has items checked as subscribed to. It is expected that all items in the subscriptionList will be unchecked.
When I step through the loop of pagereferences being unsubscribed the user.SubscriptionInfo reflects the items being removed. But when the subscriptionList web control renders they're all back there :-(
I have attempted moving the unsubscribe code to overrides of the onInitComplete and even onPreInit events so that the work is complete before the subscriptionList is bound - but to no avail.
Any pointers as to where I'm going wrong with this would be appreciated.
Might be that you need to specify the languagebranch of the page you're unsubscribing, like so:
user.SubscriptionInfo.Unsubscribe(yourpageref, "en"); // must be the same language code that you subscribed to
Thanks Arild - but no dice.
I had encountered that UnSubscribe must match the language. Regardless I had covered that at one stage by being tripley sure:
I think (but clearly am not certain about things here) that it is tied to the SubscriptionList web control binding before I remove the subscriptions. My next approach will be to redirect FROM a service that does the initial UnSubscribe TO the page with the subscription list control. I know that the Unsubscribe works in other customised circumstances but am bamboozled by this one. Will report back after implementing the redirection approach - but currently on different task.
My point was that if a language branch was specified when you SUBSCRIBED to the pages (e.g. user.SubscriptionInfo.Subscribe(pageref, "en")) then you'd need to specify the language branch when UNSUBSCRIBING, too. See http://blog.dileno.com/archive/200909/handling-subscription-and-languages-in-episerver/
To verify, check your aspnet_Profile table. It should contain an xml string that includes a <SubscribedPages> element. If a language branch was specified it should contain a <Languages> element.
Regarding your theory in databinding, you should be able to debug that easily by checking the database xml string mentioned above when stepping through your code after the unsubscribe() call to see if the page was successfully unsubscribed.