I’m using a Timer created in new sessions to log-off users based on some conditions. When the timer fires everything goes well, except when I try to call “LoginPage.Show()”, which throws a NiObjectException.
Is it possible to direct a user to a WebPage via Methods in a Session?
Update: I think WebTimer has to be created in a Page and not Session, so I’m rolling back to simple ‘Timer’ in the Session property. Still caused debugger to catch exception when trying to call .Show() of a WebPage.
A question about WebTimer… does it require to be created in a WebPage (vs. in a Session), and doesn’t it fall out of scope whenever a page is navigated away from? (e.g. when Close is called on a Page)
Good question: In theory I think you could create a new WebTimer as a session variable, but I’ve never tried it.
If you can’t get WebTimer to work as a session variable, here’s another way you can do it - add this function to your app:
Private Sub ShowLoginPage(whichSession as variant)
// shows a loginPage for an active session
#Pragma DisableBackgroundTasks
For i As Integer = 0 To App.SessionCount - 1
var sess as session = App.SessionAt(i)
if sess <> whichSession then
continue
end if
// Without creating a WebSessionContext here, creating
// the page would fail triggering a SessionNotAvailableException.
var context As New WebSessionContext(sess)
// Because we have a context, we can create a new
// WebPage and assign it to the session.
var wp as new LoginPage
context.Session.CurrentPage = wp
wp.Show // this line may not be necessary if wp.visible = true
Next
End Sub
To make this happen, you can put this code in a session event:
Timer.CallLater(1, addressOf App.ShowLoginPage, session) // this function will be called on the App's event loop, not in the session's