Access Session State Information in Applications


Session objects can be accessed anywhere in your application. In some cases, you may be able to access the .NET Session class directly.
- Pooja Daga, Technical Support Engineer, Iron Speed, Inc.

May 17, 2006
Iron Speed Designer V3.2

Introduction

Session variables can be used to pass values across pages in an application because information stored in the Session object is available throughout the session and has session scope. For example, you can store control values in session variables and access them in another web form. You can use this technique to pass information from page to page when creating a series of wizard pages to add a record. Or, you can store information about a signed in user in a session object for later use in a “WHERE “clause when initializing a control or in other custom code

Accessing Session Variables

Session objects can be set in any BaseClasses methods, events or custom functions. Similarly Session objects can be accessed anywhere in your application. In some cases, you may be able to access the .NET Session class directly. If you cannot access the Session class directly, you may need to specify its full path as follows:

In C#, to access a session value:

System.Web.HttpContext.Current.Session[“MyVariable”]
(string) System.Web.HttpContext.Current.Session[“MyVariable”]

In C#, to set a session value:

System.Web.HttpContext.Current.Session[“MyVariable”] = “NewValue”

In Visual Basic .NET, to access a session value:

System.Web.HttpContext.Current.Session(“MyVariable”)
System.Web.HttpContext.Current.Session(“MyVariable”).ToString()

In Visual Basic .NET, to set a session value:

System.Web.HttpContext.Current.Session(“MyVariable”) = “NewValue”

Sharing State Between Applications

Iron Speed Designer generates standard Microsoft .NET applications. If you want to share session states across applications, you may want to review some of the online help available for how to accomplish this in Microsoft .NET applications. Here are some links that you might find helpful.

http://www.asp101.com/articles/jayram/sharestate/default.asp

http://searchvb.techtarget.com/vsnetATEAnswers/0,293820,sid8_gci1011277_tax293672,00.html

Using the SessionNavigationHistory Class

You can use the .NET SessionNavigationHistory class to perform actions in pages based on where your user came from in the application. For example, you can obtain the previous URL in the SessionNavigationHistory list using the GetPreviousRequest method. Here’s how to define and use the SessionNavigationHistory class:

Dim str As BaseClasses.Web.SessionNavigationHistory = Me.GetSessionNavigationHistory
Dim stry As BaseClasses.Web.SessionNavigationHistory.RequestInfo = str.GetPreviousRequest()

About the Author

Pooja Daga
Technical Support Engineer, Iron Speed, Inc.

Pooja has experience developing Web applications using .NET technology. She started her career with PCS, a leading software services company headquartered in India and has been with Iron Speed since 2005.

Pooja holds an M.S. degree in Computer Application and a B.S. degree in Electrical engineering from Maharaja Sayajirao University in India.



  Privacy Statement