1

We have developed a custom unsubscribe functionality.

So, instead of Unsubscribe.aspx which is by default, we would like the control to hit Newsletter.aspx.

The redirection is proper and with RedirectUrl.aspx along with ec_eq. However when it actually redirects to Newsletter.aspx the request does not have ec_eq in the query string.

Any configuration issue?

Any help is much appreciated.

  • Hi Sujana/Pete, I'm trying to recirect to my custom unsubscribe page through RedirectUrl.aspx but unable to do so. Could you suggest how exactly you achieved this? Thanks. – Dash Jul 18 at 3:17
2

The ec_eq query string parameter is the encrypted query string and is handled via the RedirectUrl.aspx process which handles the decryption of those parameters.

What's more important is that you want to carry over query parameters that are in the decrypted in the <redirectUrl> pipeline. Because you are creating a custom Unsubscribe page that is NOT called Unsubscribe.aspx you need to specify which parameters you want to carry over in the <internalCarryoverFields> processor of the <redirectUrl> pipeline.

<redirectUrl>
<!--
 Retrieves the message item associated with the redirect event. 
-->
<processor type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.GetMessage, Sitecore.EmailCampaign.Cd" resolve="true"/>
<!--
 Determines whether the link provided in the request is a reference to a page on the local web site. 
-->
<processor type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CheckInternalLink, Sitecore.EmailCampaign.Cd" resolve="true"/>
<!--  Constructs the URL to redirect the request to.  -->
<processor type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.SetRedirectToUrl, Sitecore.EmailCampaign.Cd" resolve="true">
<internalCarryoverFields hint="list:AddInternalCarryoverField">
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.MessageId']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.AnalyticsContactId']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.ContactIdentifierSource']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.ContactIdentifierIdentifier']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.Campaign']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.TargetLanguage']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.TestValueIndex']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
<carryoverField type="Sitecore.EmailCampaign.Cd.Pipelines.RedirectUrl.CarryoverField, Sitecore.EmailCampaign.Cd">
<param ref="settings/setting[@name='QueryStringKey.EmailHistoryEntryId']/@value" desc="fieldKey"/>
<param desc="urlPattern">
SubscriptionPreferences.ashx|.*ConfirmSubscription.aspx|.*Unsubscribe.aspx|UnsubscribeFromAll.aspx.*|.*sc_pd_view=1.*
</param>
</carryoverField>
</internalCarryoverFields>
</processor>

Adding your Newsletter.aspx page to the urlPattern parameters will allow the fields you are looking for in your Newsletter.aspx page to be available.

-1

I am developing a similar functionality where I will have an Unsubscribe link on my newsletter emails which should redirect to my page where the contact will be unsubscribed from a third-party system first and if the task is successful then it should continue with unsubscribe on our system. This is how I achieved this:

  1. Created a controller rendering.
  2. Added rendering to my custom page.
  3. Changed the unsubscribe link to point this new page.

In the model, I have used the below code:

public string EmailId { get; set; }
        public string HostName { get; set; }
        public Language Language { get; set; }


        public string UnsubscribeContactsAndRedirect(HttpRequestBase request)
        {
            if (!Sitecore.Context.PageMode.IsExperienceEditor && !Sitecore.Context.PageMode.IsExperienceEditorEditing)
            {
                EmailId = Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails")
                    .Entries[Tracker.Current.Contact.GetFacet<IContactEmailAddresses>("Emails").Preferred].SmtpAddress;
                if (request.Url != null) HostName = request.Url.AbsoluteUri.Replace(request.Url.LocalPath, "");
                Language = GetSiteDefaultLanguage();

                if (true)//will be replaced by Third-party call
                {
                    Guid messageId = GetMessageId();
                    if (messageId == Guid.Empty)
                    {
                        return "/"; // Error Page for unsuccessful unsubscribe
                    }
                    string output = ClientApi.UnsubscribeFromAll(new XdbContactId(Tracker.Current.Contact.ContactId), messageId);
                    return output;
                }
            }
            return "/";
        }


        private Guid GetMessageId()
        {
            NewsletterSettingsItem newsletterSettings =
                Core.Site.Settings.GetSiteSettingCustomItem<NewsletterSettingsItem>(Sitecore.Context.Item);

            if (newsletterSettings != null)
            {
                if (NewsletterSettingsItem.IsValid(newsletterSettings))
                {
                    if (newsletterSettings.ConfirmSubscriptionMail?.Item != null)
                        if (!newsletterSettings.ConfirmSubscriptionMail.Item.ID.IsNull)
                            return newsletterSettings.ConfirmSubscriptionMail.Item.ID.ToGuid();
                }
            }
            return Guid.Empty;
        }


        private Language GetSiteDefaultLanguage()
        {
            var siteDefaultLanguageName = string.IsNullOrEmpty(Sitecore.Context.Site.Properties["language"])
                ? "en"
                : Sitecore.Context.Site.Properties["language"];

            var siteDefaultLanguage = LanguageManager.GetLanguage(siteDefaultLanguageName);
            return siteDefaultLanguage;
        }
    }

In the controller, I have this:

UnsubscribeContactsModel unsubscribeContactsModel = new UnsubscribeContactsModel();
            return RedirectPermanent(unsubscribeContactsModel.UnsubscribeContactsAndRedirect(Request));

I am reading required values either from Context or my newsletter settings item that is storing some other important settings for me.

I hope this helps.

  • 1
    Hi Somnath, I'm downvoting, not because it's a bad quality answer, but because I disagree with how you are getting your message ID. You should be getting the message ID from the query string parameters, that come out of the Redirect URL pipeline, otherwise, you will never be certain that you actually have the right message ID. You also have some custom patterns (Core.Site.Settings...) that is not standard practice for other users. – Pete Navarra Apr 16 at 18:59
  • Hi Pete, Thanks for the feedback. My requirement is different here because in my scenario, the target is to add the user to the optout list of the specific country regardless of which message he clicked the unsubscribe link from. I have multi-site setup where every country has its own optout and EXM root so I am setting up a dummy message and using its message id. – Somnath Dutta Apr 16 at 19:12
  • Anytime someone has to explain a requirement and use the word "dummy" in that requirements, makes me wonder if the requirement is actually a good requirement. In your example, you could still use the code you provided, and you can still use a message id that is provided through the carryover fields, and you can still use the API... But you don't need the "GetMessageId" method at all. So, using my answer, registering your Unsubscribe page to the <redirectUrl> pipeline, and then using the value of the message from the query parameter, will satisfy your requirement. – Pete Navarra Apr 16 at 19:45
  • BTW, welcome to Stack Exchange, and I really appreciate you providing answers and inputs. So please do not let my feedback be a deterrent from you continuing to participate. – Pete Navarra Apr 16 at 19:46
  • Hi Pete, Thanks again. I tried the approach you suggested above. I can carry forward the query string to the custom page but I am not able to extract the MessageId and ContactId from it as it seems to be null. I am using Sitecore 8.2 Update 2 and EXM 3.4.1. My Querystring looks like this: sitecore.local/sitecore/… – Somnath Dutta Apr 16 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.