Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Audit the Current User or Host Identity (XPO)

If you build a business application that is intended for use by several end users at the same time, you need to get information on who made a particular change. For this purpose, the CurrentUserName property of the application’s Security System is passed to the Audit Trail system. If you do not use the XAF Security System, handle the QueryCurrentUserName event to specify the user name for audit records. In an XAF Windows Forms application, you can get the user name from the WindowsIdentity object. In an XAF ASP.NET Web Forms application, you can use the value returned by the HttpContext.Current.Request.UserHostAddress property. The following code sample demonstrates how this can be implemented.

File: MySolution.Win\Program.cs, MySolution.Web\Global.asax.cs

using System.Security.Principal;
// ...
static void Main() {
    MySolutionWindowsFormsApplication application = new MySolutionWindowsFormsApplication();
    // ...
    // Subscribe to the QueryCurrentUserName event of the AuditTrailService instance
    AuditTrailService.Instance.QueryCurrentUserName += 
       new QueryCurrentUserNameEventHandler(Instance_QueryCurrentUserName);
    application.Setup();
    application.Start();
    // ...
}
static void Instance_QueryCurrentUserName(object sender, QueryCurrentUserNameEventArgs e) {
    e.CurrentUserName = WindowsIdentity.GetCurrent().Name;
}