Context.Session Object

Description

Context.Session object properties and methods.

The Context.Session object contains properties and methods available for working with a server session. On the stand-alone application server session data is stored in memory in the same process as the application server. On IIS session data can be stored in one of many different ways. Session data can be stored in process like the stand-alone application server, in a state server which is another process on the same machine as the web server, or in a database (SQL or NoSql) depending on the session state provider that is selected for the application. Methods on the session object may have different performance characteristics depending on the session storage that is used.

The Context.Session object has a CallResult property. Use this property to see if a method call or property get succeeds before using a method's returned value or property's value. See the following examples:
dim errorMsg as C = ""
Context.Session.Add("lastVisitedPage", "secret")
if .not. Context.Session.CallResult.Success then
     'Note: This error is most likely caught and handled and does not cause a page error. 
     error_generate(Context.Session.CallResult.Text) 
end if

Properties

CallResultCallResult

Context.Session.CallResult is used to check the success or failure of a method call or property get or set in the Context.Session object. See the note in the Context.Session class description above for more details and example. Read Only

CookieModeSystem::Web::HttpCookieMode

Context.Session.CookieMode indicates whether the application is configured for cookieless sessions.

Count Numeric

Context.Session.Count is the number of items in the session-state collection. Read Only.

IsCookielessLogical

Context.Session.IsCookieless indicates where the session id is returned to the client. If .T. the session id is added to the URL. Otherwise, the session id is stored in a cookie. Read Only.

IsNewSessionLogical

Context.Session.IsNewSession if .T. indicates the session was created during the current request. Otherwise, the session was created by some prior request. Read Only.

IsReadOnlyLogical

Context.Session.IsReadOnly if .T. indicates the session is read-only. Otherwise, the session is read-write.

IsSynchronizedLogical

Context.Session.IsSynchronized if .T. indicates that access to the session-state variables is thread safe. Otherwise, manual synchronization of session-state variable access needs to be done. Read Only

KeysSystem::Collections::Specialized::NameObjectCollectionBase::KeysCollection

Context.Session.Keys is a collection of all the keys in the session-state. Read Only.

ModeSystem::Web::SessionState::SessionStateMode

Context.Session.Mode specifies how the session-state is stored. Read Only.

SessionIdCharacter

Context.Session.SessionId is the unique identifier for the session. Read Only

TimeoutNumeric

Context.Session.Timeout gets or sets the time, in minutes, for a session to be terminated due to inactivity. Read Write.

TimestampTime

Context.Session.Timestamp is the timestamp for when the session was created. The value is local time on the server. Read Only.

UniqueDataKeyCharacter

Context.Session.UniqueDataKey generated a unique value each time it is accessed. The value is the 32 digits of a Guid prepended with "DTA" resulting in a value that looks like this: DTA114ea94b16924e30ace6bef15c75d8f4. Read Only.

VariablesPointer

Context.Session.Variables is the way to access session-state collection values directly. Using Context.Session.Variables.MySessionVar = "MySessionVarValue" is equivalent to using Context.Session.Add("MySessionVar", "MySessionVarValue"). Note that Context.Session.MySessionVar is also equivalent to Context.Session.Variables.MySessionVar, but that Context.Session.Variables.MySessionVar is preferred. See an example .a5w page below.

The Server Programming Changes for Version 11 states that session variables can only be strings and that other variables types are not supported and may not work as expected. This also means that dots (".") are not allowed in the session variable name. That is, Context.Session.Variables.MySessionVar.FirstName is not allowed.
<html>
<head> </head> 
<body> 
<pre>
<%a5 
  Context.Session.Variables.ASessionVar = "Value for ASessionVar." 
  Context.Session.Add("AnotherSessionVar", "Value for AnotherSessionVar.")
  ? *html_escape(property_to_string(Context.Session.Variables)) + crlf() 
  Context.Session.SaveData("ASessionVar", "Changed value for ASessionVar.") 
  ?*html_escape(property_to_string(Context.Session.Variables)) + crlf() 
%> 
</pre>
</body>
</html>

Methods

Abandon Method

terminates the current session.

Add Method

Adds a named value to the session-state collection.

Clear Method

Empties the entire session-state collection.

DeleteSessionFile Method

Deletes the value session-state key from the session-state collection under IIS.

FormatFileDataURL Method

Returns a URL suitable for a browser to retrieve a session file.

GetData Method

Gets the value of a specific key from the session-state collection.

GetDataFromFile Method

Gets the value of a key from the session-state collection.

GetSQLCredentials Method

Returns the SQL username and password used for SQL connections.

Remove Method

Removes a named value to the session-state collection.

RemoveAll Method

Alias of Context.Session.Clear().

RemoveAt Method

Removes the item at the specified 0-based index from the session-state collection.

SaveData Method

Sets the value of a key in the session-state collection.

SaveDataAsFile Method

Saves the value to the session-state collection under IIS.

SaveFileToSessionFile Method

Saves source file content to the session-state collection under IIS.

SaveSessionFileToFile Method

Saves the contents of the session-state key to the destination file under IIS.

SetSQLCredentials Method

Sets the SQL username and password used for SQL connections.