Read or modify the session properties

You can change the session user and session locale. You can also run methods at the user change event.

  • To change the session user, use Session.ChangeUserto authenticate another user in the session. The user name and password are passed as arguments bool ChangeUser(string username, string password); .
  • To change the session locale, create a string array by using the new string[] syntax.
    Important: Be sure to create an array. The session requires a fallback locale.
    This example illustrates how to set the locale to international English.
    Session.LocaleId = "en-US";
  • To run methods at the user change event, use the UserChange event handler, supplied by the Session class.
    Important: Always cancel the subscription in the Stop() method to avoid a memory leak.
    This example illustrates how to have the Session_UserChange method executed at each user change, until cancellation of the subscription.
    public override void Start()
    {
        Session.UserChange += Session_UserChange;
    }
    
    private void Session_UserChange(object sender, UserChangeEventArgs e)
    {
        Log.Info(e.newUser.BrowseName);
    }
    
    public override void Stop()
    {
        Session.UserChange -= Session_UserChange;
    }

    The method generates a log that contains the BrowseName of the new user

    The UserChangeEventArgs data type is a class that displays these properties:
    newUser
    Represents new user nodes.
    oldUser
    Represents old user nodes.