Created On: 09 December 2010
Problem:
When creating an ASP.NET Web Site in Visual COBOL a run-time error occurs when trying to store an object into the Session object.
This is ocurring because the Session object is not being instantiated so a NULL reference error occurs.
Example: code behind program snippet for web page:
class-id ShoppingCart is partial inherits type Page.
set mycontext to type System.Web.HttpContext::Current
set mystring to "TestSession"
set mycontext::Session::Item("TestItems") to mystring
*> An error occurs on the above statement
This is ocurring because the Session object is not being instantiated so a NULL reference error occurs.
Example: code behind program snippet for web page:
class-id ShoppingCart is partial inherits type Page.
set mycontext to type System.Web.HttpContext::Current
set mystring to "TestSession"
set mycontext::Session::Item("TestItems") to mystring
*> An error occurs on the above statement
Resolution:
Creating an ASP.NET Web Site in COBOL is quite different than creating an ASP.NET Web Project in that the latter has a Global.asax that handles Session_Start events that populates the session object.
However, a simple change to the web page code behind file ".cbl", will allow you to get the same desired behavior.
Just add :
implements type System.Web.SessionState.IRequiresSessionState.
to the class-id of the page.
Example:
class-id ShoppingCart is partial inherits type Page implements type System.Web.SessionState.IRequiresSessionState.
This will allow you to store and retrieve objects into the Session object by using code like:
set mycontext to type System.Web.HttpContext::Current
set mystring to "TestSession"
set mycontext::Session::Item("TestItems") to mystring
However, a simple change to the web page code behind file ".cbl", will allow you to get the same desired behavior.
Just add :
implements type System.Web.SessionState.IRequiresSessionState.
to the class-id of the page.
Example:
class-id ShoppingCart is partial inherits type Page implements type System.Web.SessionState.IRequiresSessionState.
This will allow you to store and retrieve objects into the Session object by using code like:
set mycontext to type System.Web.HttpContext::Current
set mystring to "TestSession"
set mycontext::Session::Item("TestItems") to mystring
Incident #2490676