This explanation assumes knowledge of ASP.NET and provides a basic RedBack example. This example first connects to a uObject RBO (Employee) and then uses the RedBack Session ID when creating the second RBO on the page it redirects to. The idea is to reuse the Session ID from the first stateful object you create when you create all your other stateful objects (this can facilitate garbage college). First of all, we create a RBO and then redirect to another page, passing the Session ID.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim sessionID as String ' object for Employee Dim oEmp as New REDPAGESLib.RedObject() oEmp.Open2("rbexamples", "EXMOD:Employee", "", "", "") 'preserve the session id so that we can associate other RBOs with this session sessionID = oEmp.SessionID ' Add RedBack session ID to cookies (alternatives are to set in app session or pass on query string) Dim objCookie As HttpCookie objCookie = New HttpCookie("RB_SessionId",sessionID) Context.Response.Cookies.Add(objCookie) ' now redirect to example page ' where it will pick up RedBack session id from cookie Response.redirect("uobjectex2.aspx") End Sub Now we'll either use the Session ID passed when creating the RBO or use the stored handle for the second RBO (if already created, i.e. not first time in). The session ID is used when openning the CustomerMaint RBO. In this way we associate state with the current session.
'Handle Stateful using sessionid and object handle in cookies For Each strVariable in Context.Request.Cookies() If strVariable = "RB_SessionId" Then RB_SessionId = Context.Request.Cookies(strVariable).Value End If If strVariable = "RB_" & ROName Then prevRBHandle = Context.Request.Cookies(strVariable).Value if prevRBHandle <> "" then RBHandle = prevRBHandle end if End If Next Try ro = New REDPAGESLib.RedObject() ro.Open2(DatabaseName, RBHandle, Username, Password, RB_SessionId) IsOpen = True Context.Session(ROName) = ro If Stateless = "N" Then 'Handle Stateful objCookie = New HttpCookie("RB_SessionId",ro.SessionId) Context.Response.Cookies.Add(objCookie) objCookie = New HttpCookie("RB_" & ROName,ro.RBOHandle) Context.Response.Cookies.Add(objCookie) End If Catch ex As Exception 'Set Message label with error message throw ex End Try See the rbexamplesnetvb directory to review the page's entire source code. |