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.ChangeUser
to authenticate another user in the session. The user name and password are passed as argumentsbool 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 theSession
class.Important: Always cancel the subscription in theStop()
method to avoid a memory leak.This example illustrates how to have theSession_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 userTheUserChangeEventArgs
data type is a class that displays these properties:newUser
- Represents new user nodes.
oldUser
- Represents old user nodes.