Skip to main content
.NET 8.0+

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

SecurityStrategyComplex.CustomInitializeNewUser Event

Occurs when a user is automatically created.

Namespace: DevExpress.ExpressApp.Security

Assembly: DevExpress.ExpressApp.Security.v24.2.dll

#Declaration

public event EventHandler<CustomInitializeNewUserEventArgs> CustomInitializeNewUser

#Event Data

The CustomInitializeNewUser event's data class is DevExpress.ExpressApp.Security.CustomInitializeNewUserEventArgs.

#Remarks

Use this event to setup an automatically created user and link it to necessary roles. Set the Handled parameter to true to disable the default initialization.

When the default initialization is enabled, the Security System does the following:

  1. Tries to find an object of the SecurityStrategyComplex.RoleType with a Name property value equal to a SecurityStrategyComplex.NewUserRoleName‘s value. If this role was not found, creates a new role with the name specified in the NewUserRoleName property and sets the role’s IsAdministrative property to true.
  2. Adds a newly created user to the Users collection of the role found or created at the previous step.

The following example handles the CustomInitializeNewUser event and sets a value to a custom property of a new user:

public void ConfigureServices(IServiceCollection services) {
    // ...
    services.AddXaf(Configuration, builder => {
        //...
        builder.Security
            .UseIntegratedMode(options => {
              // ...
              options.Events.OnSecurityStrategyCreated = (e) => 
              { ((SecurityStrategyComplex)e).CustomInitializeNewUser += Startup_CustomInitializeNewUser; };
            })
    });
}

private void Startup_CustomInitializeNewUser(object sender, CustomInitializeNewUserEventArgs e) {
    ((ApplicationUser)e.User).CustomProperty = "newproperty";
}
See Also