Back to Devexpress

XafApplication.LastLogonParametersReading Event

expressappframework-devexpress-dot-expressapp-dot-xafapplication-459839dc.md

latest8.3 KB
Original Source

XafApplication.LastLogonParametersReading Event

Occurs before loading the last logon parameters from the settings storage to the logon object.

Namespace : DevExpress.ExpressApp

Assembly : DevExpress.ExpressApp.v25.2.dll

NuGet Package : DevExpress.ExpressApp

Declaration

csharp
public event EventHandler<LastLogonParametersReadingEventArgs> LastLogonParametersReading
vb
Public Event LastLogonParametersReading As EventHandler(Of LastLogonParametersReadingEventArgs)

Event Data

The LastLogonParametersReading event's data class is LastLogonParametersReadingEventArgs. The following properties provide information specific to this event:

PropertyDescription
HandledGets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs.
LogonObjectSpecifies the object that specifies the logon parameters to be displaed in a logon Window.
SettingsStorageProvides access to the settings storage which is used to load logon parameters.

Remarks

A logon Window contains a View which represents a Security System‘s logon parameters. In a Windows Forms application, this View shows the last user’s parameters. To load these parameters, a special storage object is created. It loads logon parameters from the LogonParameters file. When the application is launched for the first time, the logon parameters storage is empty. ASP.NET Core Blazor applications do not create the last user’s parameters storage by default.

You can handle the LastLogonParametersReading event to load custom logon parameters. Use the handler’s LastLogonParametersReadingEventArgs.SettingsStorage parameter to load the last logon parameters to the object specified by the LastLogonParametersReadingEventArgs.LogonObject parameter. The example below demonstrates how to set the user name shown when the application is launched for the first time to “Guest”.

In a Windows Forms application project’s Program.cs file:

csharp
static void Main() {
    // ...
    winApplication.LastLogonParametersReading += 
        new EventHandler<LastLogonParametersReadingEventArgs>(
            winApplication_LastLogonParametersReading);
    // ...
    winApplication.Setup();
    winApplication.Start();
    // ...
}
static void winApplication_LastLogonParametersReading(
    object sender, LastLogonParametersReadingEventArgs e) {
    if (string.IsNullOrEmpty(e.SettingsStorage.LoadOption("", "UserName"))) {
        e.SettingsStorage.SaveOption("", "UserName", "Guest");
    }
}

Note

The same task can be accomplished by handling the XafApplication.LastLogonParametersRead and modifying the logon parameters which are already loaded from the settings storage. Additionally, you can handle the XafApplication.LastLogonParametersWriting event to specify the custom logic applied when saving logon parameters to the settings storage.

Default parameter loading can be prevented by setting the handler’s Handled parameter to true. When you set this parameter to true and add no other code to the LastLogonParametersReading event handler, the logon parameters shown in the logon window will always be empty. If it is required to implement a custom logic, add the corresponding code to the event handler and set Handled to true, to indicate that it is not required to perform the default process of loading the last logon parameters from the settings storage to the logon object.

When using custom logon parameters, you can implement the ICustomObjectSerialize interface. The logon parameters saving and loading can be handled in the ICustomObjectSerialize.ReadPropertyValues and ICustomObjectSerialize.WritePropertyValues methods.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the LastLogonParametersReading event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-separate-employees-data-in-different-departments-using-security-permissions/CS/MainDemo.Win/Program.cs#L24

csharp
AuditTrailService.Instance.QueryCurrentUserName += new QueryCurrentUserNameEventHandler(Instance_QueryCurrentUserName);
winApplication.LastLogonParametersReading += new EventHandler<LastLogonParametersReadingEventArgs>(winApplication_LastLogonParametersReading);
if(ConfigurationManager.ConnectionStrings["ConnectionString"] != null) {

xaf-separate-employees-data-in-different-departments-using-security-permissions/VB/MainDemo.Win/Program.vb#L22

vb
AddHandler AuditTrailService.Instance.QueryCurrentUserName, New QueryCurrentUserNameEventHandler(AddressOf Instance_QueryCurrentUserName)
AddHandler winApplication.LastLogonParametersReading, New EventHandler(Of LastLogonParametersReadingEventArgs)(AddressOf winApplication_LastLogonParametersReading)

See Also

LastLogonParametersRead

LastLogonParametersWriting

CreateCustomLogonParameterStore

ICustomObjectSerialize

Customize Standard Authentication Behavior and Supply Additional Logon Parameters (.NET Applications)

XafApplication Class

XafApplication Members

DevExpress.ExpressApp Namespace