在 Kentico CMS 中,如何以编程方式为用户订阅时事通讯?
完成自定义付款表单后,我添加了两个用户角色、一个徽章和两个朋友。所有这些更改都运行良好并填充到用户对象和相应的数据库表中。当我使用下面的代码(从 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!";
Upon completion of a custom payment form I add two user roles, a badge, and two friends. All of those changes work well and populate to the User object and corresponding database tables. When I use the below code (copied and altered from Kentico CMS install) I get IsSubscribed == true, but the user never appears to be subscribed. Any ideas?
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!";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了!构建订阅者后,您必须将它们添加到新闻通讯中。你必须使用:
Got it! After you build the Subscriber you have to add them to the Newsletter. You have to use: