3

完成自定义支付表单后,我添加了两个用户角色、一个徽章和两个朋友。所有这些更改都运行良好并填充到用户对象和相应的数据库表中。当我使用以下代码(从 Kentico CMS 安装复制和更改)时,我得到 IsSubscribed == true,但用户似乎从未被订阅。有任何想法吗?

int newsletterId = 3;
Subscriber sb = SubscriberProvider.GetSubscriber("cms.user", currentUser.UserID);
    if (sb == null)
     {
            // Create new subscriber
            sb = SaveSubscriber(); // CreateSubscriber(value[0], itemId);
      }
      // If subscriber exists and is not subscribed, subscribe him
      if ((sb != null) && (!SubscriberProvider.IsSubscribed(sb.SubscriberID, newsletterId)))
      {
         try
         {
             SubscriberProvider.Subscribe(sb.SubscriberID, newsletterId, DateTime.Now, false);
             lblTroubledUser.Text = "shoulda been subscribed to newsletter";
         }
         catch
         {
              lblTroubledUser.Text = "problem subscribing to newsletter";
         }
      }
      else
            lblTroubledUser.Text = (!SubscriberProvider.IsSubscribed(sb.SubscriberID, newsletterId)) ? "sb is null" : "already subscribed to newsletter!";
4

1 回答 1

5

知道了!构建订阅者后,您必须将它们添加到时事通讯中。你必须使用:

SubscriberNewsletterInfoProvider.AddSubscriberToNewsletter(sb.SubscriberID, newsletterId, DateTime.Now);
于 2009-08-25T19:14:02.847 回答