Subscribe to comments of blogs: Subscribe an email address to comments

NEW TO SITEFINITY?

After you create and Subscribe to comments of blogs: Register the new comment notifications strategy, you need to obtain the subscriber’s email address by using a form submit or a custom web service.

Obtain the thread key of the comments, using the blog post ID. Use the following sample:

using System;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Comments;
using Telerik.Sitefinity.Web.UI;
namespace SitefinityWebApp
{
public class GetThreadKey
{
public static string threadKey;
private readonly Guid blogId = new Guid("4c53766c-a903-4e53-a9cd-d73e34c71980");
public void GetThreadKeyByBlogPost(Guid blogPostId)
{
//gets an instance of the comments service
var cs = SystemManager.GetCommentsService();
//adds an instance to the comment filter
var filter = new CommentFilter();
//gets the thread related to the blog post
var language = SystemManager.CurrentContext.Culture.Name;
string getThreadKey = ControlUtilities.GetLocalizedKey(blogPostId, language);
threadKey = getThreadKey;
}
}
}

Next, subscribe to the respective thread type by using the Subscribe method of the comment service that calls a method with the same signature from the currently registered ICommentNotificationsStrategy. To subscribe, copy the following code in the Bootstrapper.Bootstrapped Sitefinity event that you can use in the Global.asax file or, depending on your needs, in any widget, service, and so forth: 

using System;
using Telerik.Microsoft.Practices.Unity;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Blogs.Model;
using Telerik.Sitefinity.Data;
using Telerik.Sitefinity.Services;
using Telerik.Sitefinity.Services.Comments.Notifications;
namespace SitefinityWebApp
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
}
private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
{
ObjectFactory.Container.RegisterType<ICommentNotificationsStrategy, CustomCommentNotificationsStrategy>(new ContainerControlledLifetimeManager());
var commentService = SystemManager.GetCommentsService();
commentService.Subscribe(new CustomSubscriptionData()
{
SubscriberEmail = "test@mail.com",
ThreadType = typeof(BlogPost).FullName,
ThreadKey = GetThreadKey.threadKey
});
}
}
}

Want to learn more?

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?