How To…Determine Web SessionID

Question

“How can I determine the SessionID for each web request?”

Solution

The following example shows how to use the webTier and WebSessionManager to determine the SessionID for each request.

Download: WebTierSessionID.zip

Sample Delphi code:

uses
  rsWebRequest,
  rsWebSessionManager;

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  lWebRequest: TrsWebRequest;
begin

  // create a TrsWebRequest object
  lWebRequest := rsWebTier1.CreateWebRequest(Request.QueryFields, Request.Content);

  // if the session does not exists, use the global WebSessionManager to create one
  if not rsWebTier1.SessionExists(lWebRequest) then
    gWebSessionManager.GetSessionForRequest(lWebRequest);

  // at this point we have a session id assigned
  // lWebRequest.SessionID;

  // process the web request
  Response.Content := rsWebTier1.ProcessWebRequest(lWebRequest);

end;