I want to craete session object in my application .please tell me how to create and use session object.

You need to create a Session Object as every time someone visits your site a session is created by default. You can think of the session as a big hashtable with keys to retrieve the contents, one important thing to remember though is that Sessions dont last forever, so if someone left a page open for a long time the session would expire and the stored items would be removed

One simple example of using the Session Object would be:

string test = "test";
Session["mySessionObject"] = test;

So there it is, we already added an item to the Session. So now we probably want to look at that again later, a good tip here is that sometimes the Session object expires so always check the session object exists before casting it to its original type:

if(Session["mySessionObject"] != null)
{
string myVariable = (string) Session["mySessionObject"]; 
}

I am newbie,Can anyone post program using state mangement techniques

I am newbie,Can anyone post program using state mangement techniques

basically there are four ways to handle state management :

1) viewstate
2) sessionstate
3) cookies
4) database

viewstate provides state management during postbacks

session state provides global variables that you can reach from all the pages in your application domain.

cookies are text files that are kept in the client's harddrive so you can read those during each page request

Simple way to use Session and Display;
string str = "sample";
Session["DATA"] = str;
Response.Write(Session["DATA"].toString());

This article has been dead for over six months. Start a new discussion instead.