Skip to main content
.NET 6.0+

ICustomObjectSerialize Interface

Declares methods implemented by classes that interact with the settings storage.

Namespace: DevExpress.ExpressApp.Utils

Assembly: DevExpress.ExpressApp.v24.1.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public interface ICustomObjectSerialize

Remarks

The ICustomObjectSerialize interface exposes two methods. The ICustomObjectSerialize.ReadPropertyValues method handles loading the values from the settings storage. The ICustomObjectSerialize.WritePropertyValues method handles saving the values to the settings storage.

You can implement the ICustomObjectSerialize interface in an AuthenticationStandardLogonParameters descendant, to customize the process of loading and saving logon parameters. The code below illustrates how to provide end users with the ability to choose whether to input a password each time the Logon Window is displayed, or input a password once, and remember it in the logon parameters storage.

using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Utils;
// ...
[DomainComponent]
public class MyLogonParameters : AuthenticationStandardLogonParameters, ICustomObjectSerialize {
    private bool rememberPassword;
    public bool RememberPassword {
        get { 
           return rememberPassword; 
        }
        set { 
            rememberPassword = value;
        }
    }
    public void ReadPropertyValues(SettingsStorage storage) {
        UserName = storage.LoadOption("", "UserName");
        Password = storage.LoadOption("", "Password");
        RememberPassword = storage.LoadBoolOption("", "RememberPassword", false);
    }
    public void WritePropertyValues(SettingsStorage storage) {
        storage.SaveOption("", "UserName", UserName);
        storage.SaveOption("", "Password", RememberPassword ? Password : "");
        storage.SaveOption("", "RememberPassword", RememberPassword.ToString());
    }
}

Note

You may need to add a reference to the DevExpress.ExpressApp.Security.24.1.dll assembly.

Take note of the ICustomObjectSerialize.ReadPropertyValues and ICustomObjectSerialize.WritePropertyValues methods implementation. In the ReadPropertyValues method, the logon parameter values are loaded via the SettingsStorage.LoadOption and SettingsStorage.LoadBoolOption methods. In the WritePropertyValues method, the logon parameter values are saved via the SettingsStorage.SaveOption method. Non-string values should be converted to strings before saving. The RememberPassword property will be displayed in the Logon Window, together with the UserName and Password properties exposed by the AuthenticationStandardLogonParameters ancestor class. However, the RememberPassword property is not included in the authentication process.

To use custom logon parameters in the XAF application, specify the LogonParametersType property via the Application Designer.

LogonParameters_Custom

Run the application.

LogonSavePassword

Note

In an XAF Windows Forms application, the logon parameters are stored in the LogonParameters file, by default. In an XAF ASP.NET Web Forms application, the logon parameters are stored in browser cookies. A separate cookie is created for each parameter. According to the accepted naming convention, each cookie name contains the application name and the parameter name. Note that the number of cookies per domain and the amount of information allowed to be stored in a cookie is limited.

In some scenarios, it can be required to store non-string logon parameters. If a persistent object is used as a logon parameter, you can store the string representation of its BaseObject.Oid property, or anther property that has a unique value (e.g. PermissionPolicyUser.UserName). The code below illustrates how to support the ICustomObjectSerialize interface in the CustomLogonParameters class demonstrated in the How to: Use Custom Logon Parameters and Authentication topic.

using DevExpress.ExpressApp.Utils;
// ...
public class CustomLogonParameters : ICustomObjectSerialize {
    // ...
    public void ReadPropertyValues(SettingsStorage storage) {
            string userName = storage.LoadOption("", "UserName");
            Employee = objectSpace.FirstOrDefault<Employee>(e => e.UserName == userName);
    }
    public void WritePropertyValues(SettingsStorage storage) {
        storage.SaveOption("", "UserName", Employee.UserName);
    }
}

You can handle the XafApplication.LastLogonParametersRead, XafApplication.LastLogonParametersReading and XafApplication.LastLogonParametersWriting events to customize the process of saving and loading the logon parameters, instead of the approach described in this topic. Additionally, you can use custom settings storage by handling the XafApplication.CreateCustomLogonParameterStore event.

See Also