[Feature-2249] Saving Session Information

Is there a preferred way of saving the session information for a user? Usually in the web world, we can either store the session in a cookie or local storage of the machine. I understand that we can also save the information into the database and the write it back to the user upon login. I’m just wondering if there is a preferred way to do this in Ignition.

Hi @tony.petruzzi1, you can store information in the database against the user information. You can pull this from the session props for the current user, or there are some inbuilt scripting functions to query for other user’s info (which function depends on whether you are using Vision or Perspective). Not sure if this is the best way, but it’s the way I do it :slight_smile:

Additionally, if you ever want to store information for a specific device, one way is to use a fixed IP address and store information against this. This is the ‘host’ session prop.

If we wanted to go the host route, how would we apply the information when the session start? I tried putting a default value in the Session OnState event as a test, but it doesn’t get set.

session.custom.tony = ‘Tony!!!’

I have used bindings on the components you need to change. Or you can use a change script on the host prop to change another value.

what I mean is there a way to initialize the session variables on Startup? In the web world, there is usually an OnApplicationStart event or what not, that you can use to initialize session variables. I thought that the Session onStart event was such a thing, but I seem to be wrong

Unfortunately, the Session Event Scripts (in this case Startup) run in the Gateway and are triggered before the session props are evaluated. The session props are populated once the session has started.

Bindings and/or onChange scripts will update when the session prop has been populated, effectively acting like it’s on startup (but you may see a short delay). As far as I am aware there is no way to initialise the session properties before/during session startup.

That is unfortunate. You would think that by version 8 they would have something like that. I’ll see about putting in a feature request.

I may be wrong, and maybe @cmallonee or @PGriffith may be able to advise further :slight_smile:

Just for my understanding, in your use case scenario why would a binding or change script not work? I’m just curious :slight_smile:

So… Session Startup is not the correct place, because no information is really in place yet. Also, Change scripts on the auth properties won’t work because if your project requires authentication then those properties initialize with the user’s information, which does not qualify as a “change event”. If your project does NOT require authentication, then change scripts are a pretty good way to go.

I think the Page Startup Event might be a good place to put this, although you would need to include a session variable which acts as a flag to prevent multiple executions.

Something like:

if not page.session.custom.user_info_set:
    # do your DB stuff here, including setting session props
    page.session.custom.user_info_set = True
1 Like

Thank you, I will look into doing this :slight_smile:
In all honesty, I’m kind of surprised that this isn’t included already. You would figure that there would be someway to initialize a session.

We have a long-standing feature request for something like this (Login Event) which is where you would really want this logic; after the session has started and after the user properties have been applied to the session. The feature hasn’t had much traction (opened July 2019) so I expect it’ll still be awhile before it’s given consideration and implemented.