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

Recommended Answers

All 6 Replies

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

more details in sessioncookies and cookies

session is important give me also some use of it

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.