If you need to execute custom code when the Creatio application starts up or shuts down, or when a user session starts or ends, you can easily do so by creating a class that inherits from AppEventListenerBase and overriding OnAppStart, OnAppEnd, OnSessionStart, or OnSessionEnd.
Let’s take a look at a sample class that executes some code when the Creatio application starts.
using Terrasoft.Common;
using Terrasoft.Core;
using Terrasoft.Web.Common;
namespace Terrasoft.Configuration
{
public class CustomAppEventListener : AppEventListenerBase
{
protected UserConnection GetUserConnection(AppEventContext context)
{
var appConnection = context.Application["AppConnection"] as AppConnection;
return appConnection?.SystemUserConnection;
}
public override void OnAppStart(AppEventContext context)
{
base.OnAppStart(context);
var userConnection = GetUserConnection(context);
// DO SOMETHING ON APPLICATION START HERE
}
}
}
Similarly, if you need to respond to a user starting a session, you can use this same approach, however, you’ll get the UserConnection from their session so you can determine the user who started the session.
using Terrasoft.Common;
using Terrasoft.Core;
using Terrasoft.Web.Common;
using Terrasoft.Web.Http.Abstractions;
namespace Terrasoft.Configuration
{
public class CustomAppEventListener : AppEventListenerBase
{
protected UserConnection GetSessionUserConnection()
{
return HttpContext.Current.Session["UserConnection"] as UserConnection;
}
public override void OnSessionStart(AppEventContext context)
{
base.OnSessionStart(context);
var userConnection = GetSessionUserConnection();
var user = userConnection.CurrentUser;
// DO SOMETHING ON SESSION START HERE
}
}
}
The AppEventListenerBase class has the following methods available to override:
- OnAppStart
- OnAppEnd
- OnSessionStart
- OnSessionEnd
Note, I’ve used the class name “CustomAppEventListener”, however, you don’t need to name the class this. It can be named whatever you’d like.




Above article is the one that I required in my usecase.
Thanks Ryan for your contribution.
Glad it helped, Souresh!
Hi Ryan,
Is there any Event available that can be used before ‘OnSessionStart’ event to check some condition or perform some action before validating login credentials or session-start?
I don’t believe there is anything like that.
Is it possible to track when compilation started?
Newer versions of Creatio do log compilations in the CompilationHistory table. You can use that to see when a compilation starts. From externally, you could also listen for the telemetry log for a compilation (I can’t remember the logger name for that, but if you listen for telemetry logs you’ll see it when a compilation starts)
I encountered a problem, when I create a listener for this object CompilationHistory , it does not fire when compilation starts
I would assume that this object does not trigger signals (such as to start a process) since at the time this object is written to, the compilation is underway and the system and model would not be available for use. You won’t be able to use the system being compiled to respond to and do something while it’s being compiled.
From an external application you could listen for the ConfigurationBuild or Build logger (you could use Clio command-line to get the logger telemetry if needed). See https://share.customerfx.com/L1uZLE6L