You subscribe to an event that is published by a Sitefinity CMS class to write custom logic and have the logic executed when the specific event is raised. When subscribing to an event from the Sitefinity events system, you need to make sure you hook up your event handler at a proper phase during application runtime. You can do that in your Global.asax file or in a custom Subscriber class that is plugged in via the AsssemblyInfo.cs class.
Sitefinity CMS is an ASP.NET WebApplication, so you can use the standard Global.asax file approach to work with application and session-level events raised by ASP.NET or HTTP modules. Generally, you do your event subscriptions in the Global.asax file using the system Application_Start method. This method is called when the first resource in an ASP.NET application is requested and can be used to perform startup tasks. Inside the Application_Start method, you can hook up to the events, specific to the Sitefinity application lifecycle, for the purposes of your Following is an example demonstrating how to subscribe to the Sitefinity CMS Bootstrapper.Bootstrapped event that is explained in more details later in this section:
Sitefinity CMS enables you to subscribe for events using the Application_Start method of the Global.asax file. If you have custom code in the Global.asax file and you do not want to edit the file, you can subscribe to events using the PreApplicationStartMethodAttribute class of the .NET framework. The class provides expanded support for application startup.
First, you need to create a class that holds the subscription logic - the Subscriber class, for example. Next, you add the PreApplicationStartMethodAttribute class in the AssemblyInfo.cs file. Finally, from the AssemblyInfo.cs file, using the PreApplicationStartMethodAttribute class, you can initialize the Start()method of the Subscriber class. The AssemblyInfo.cs file references an assembly to be linked to during compilation of a dynamic resource.
The Subscriber class holds the subscription logic for a particular event, for example a Comment event (ICommentEvent).
In the sample code above, upon application startup, the static method Start() will be called. You use the Bootstrapper class and add an event handler to the Bootstrapped event. Finally, using the Sitefinity CMS EventHub, subscribe for the ICommentEvent and pass the comment event handler that will be fired.
To initialize the Start() method of the Subscriber class:
[assembly: System.Web.PreApplicationStartMethodAttribute(typeof(SitefinityWebApp.Subscriber), "Start")]
As a result, the Start() method of the Subscriber class is initialized upon application startup.
Sign up for our free beginner training. Boost your credentials through advanced courses and certification. Register for Sitefinity training and certification.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important