User Ids for Entity Tracking and Soft Deletion
Different applications identify users in different ways. There is no default way of identifying a user. So in order to store user names in the CreatedBy, UpdatedBy and DeletedBy fields, you must specify to LightSpeed how it should identify users.
To do this, set LightSpeedContext.AuditInfoMode in code, or set the auditInfo attribute in configuration. The available values are defined by the AuditInfoMode enumeration.
Setting how users are identified in configuration |
<add name="Test" |
Built-In User Identification Strategies
There are two built-in user identification strategies, HttpContext and WindowsIdentity.
· HttpContext: The user id is taken from the HttpContext.Current.User.Identity. The application should ensure that users are authenticated.
· WindowsIdentity: The user id is the Windows login of the active user.
Using a Custom Identification Strategy
Some applications have their own means of identifying users, such as a custom user database or directory. To make LightSpeed use such a custom identification method, specify the Custom AuditInfoMode, implement IAuditInfoStrategy, and set LightSpeedContext.CustomAuditInfoStrategy to an instance of that implementation.
Implementing IAuditInfoStrategy for unit testing |
public class FixedAuditInfoStrategy : IAuditInfoStrategy |
Using the custom strategy |
_context.AuditInfoMode = AuditInfoMode.Custom; |
You can also specify a custom audit information strategy in configuration using its assembly‑qualified type name. In this case the strategy class cannot take constructor parameters.
Setting a custom audit info strategy in configuration |
<add name="Test" |