what happens when browser window is closed?

I allow more than one person in an organization to use the same username / password. Anyway to check and see if one person in an organisation is already using the program?

Don’t want two people overwriting each other.

Keep a local Dictionary or similar in your App class to store current usernames/userid’s. Then when a user logs in add them to that array/dictionary. When they logout or their session closes removes them. Should give you a running list of active users.

that’s working thanks. Can’t get the username removed however. doesn’t seem to even be going to session close:

dim ok as new dialogOK
ok.lblText.text = ": " + cc.userName
addHandler ok.dismissed, AddressOf cc.doNothing
ok.show
for i as integer = 0 to app.namesInUse.ubound
if cc.userName = app.namesInUse(i) then
app.namesInUse.remove i
end if
next i

Faster:

dictionaryNamesInUse.Value(“theUserName”) = 1 // Mark him as Online

// …

if dictionaryNamesInUse.HasKey(“theUserName”) then MsgBox(“This user is On Line”)

//

dictionaryNamesInUse.Remove(“theUserName”) // Remove this one

thanks.

still can’t seem to get to session close. Doesn’t closing the window close the session?

closing the browser window doesn’t take you to session.close?

Not immediately. Sessions are allowed to live for 3 minutes after the user disconnects so if they come back, the session will still be there.

Is there anything I can use as a trigger?

A trigger to do what?

Also, there are other things that can cause a session to stay open. Like creating a reference to the Session on a web page. Since the session has a reference to each page, you’d get a circular reference which would prevent either from being destroyed.

want to warn a user that another user on the same account is using the program so they overwrite each other’s work

Iterate the Sessions using app methods. Each Session should know who is connected. See if one is.

I’ve got that using the dictionary method … I can’t get it to sign a user off when they close the browser window

You’re storing Sessions in a dictionary? That keeps a reference around, and is likely why you can’t get users to sign off. Don’t do that. Use the iterator functions in the WebApplication class.

Is this true when the WebSession.Quit Method is used?
In my experiment it seems to be the case as I cant’ have the WebSession.Close event fired after quitting a session. But there is no mention of this behaviour that I can find in the documentation.

WebSession.Quit sends a message to the browser to close and tells the WebSession object that it has expired. There is still a short period of time where the session will be alive though, at least until the next time the framework looks for expired sessions.

@John Scanlan - It sounds like the best thing for you to do is to make a system that is independent of the Sessions which keeps track of users and groups of users (so you can tell if people might be overwriting each other’s work) and when someone logs in, do the check there. My instinct is that you could use an in-memory sqlite database to keep track of this at the application level, so it’d be fast and would only exist as long as the app was actually running.

Thanks Greg, that’s good to know. May be there should be a note describing this behavior in WebSession.Quit entry in the doc.

Greg … could work, but how?

Creating an in memory database is done by creating a sqlitedatabase without setting the DatabaseFile property.

Just added: http://documentation.xojo.com/index.php/SQLiteDatabase#In-Memory_Database