Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 01:51 - Jul 21, 2007  

bc030400030

how can i make a session in asp.net?

How can i make a session for user in Asp.net 2.0? and also how can i track the user? plz give me code for it.

Categories

Answer Discussion
Tutorials

 

PeterNZ

Date:: Jul 22, 2007

Time:: 15:12

Sorry, I am not sure what exactly you want to achieve! A session is automatically created for each user. What do you want to do? Do you need session cache? Or cookies?

User tracking depends mainly on how your web page is set up? Is it using anonymous access? Do you use impersonation? Do you use windows log on? Etc. Cookies would be a mechanism to allow you to save i.e. a user id on the user's machine and transmit it to your web server etc.

One really good page with samples and how to get started is: http://samples.gotdotnet.com/quickstart/...

Cheers

Peter

Prajith

Date:: Jul 24, 2007

Time:: 13:00


Introduction
Session is a special type of variable or object that is used in state management in web applications. A web application works as a disconnected or asynchronized architecture as when a client request a page the web server hosting the requested application serves the requested page to client and then it doesn’t know about who has requested a page or if the client sends another request to server or web application it doesn’t know if the same client has sent request prior to this one.
So now in the given scenario for any dynamic web application if the application needs to track the client or user for processing, there should be some way to track the users. The web application has two most common ways to do the same, Cookies and Session.
Cookies and Session are different as
• Cookies are a piece of information stored at client machine in small files where as the session is maintained by server.
• Cookies can persist long for several days but Session has a smaller life span and at the max for one session of a browser.
Our emphasis here will be on Session only. We are not talking about any specific web technology here as the concept discussed here holds true for most of the web technologies. Just the syntax and semantics of a language differs.

Life cycle
The life span of a Session is for one browser session only, that means the session will be maintained till one browser session is on and the moment browser is closed the session for that particular browser ends. The web application fires two event in relation with Sessions such as Session_Start() and Session_End(). The names of events might differ for different programming language used. Session_Start is called when user sends a request for a web page for first time to the application and Session_End is called when the user closes the browser. So these events can be used for variable initialization and clean up jobs.
For the Session variables that developer creates to use in the application the developer decides the life span, so it comes into existence when developer explicitly creates them and goes out of scope when developer destroys it. If in any case if the developer forgets to destroy or do a clean up on session variable that he has created, the Session variable will still be lying alive with server and will be cleaned up if server or application restarts or the clean up process is run.

When is it created
Session is created when user sends a first request to the server for any page in the web application, the application creates the Session and sends the Session ID back to the user with the response and is stored in the client machine as a small cookie. So ideally the "machine that has disabled the cookies, session information will not be stored".

When is it destroyed
The Session is destroyed the moment you close the browser at user end. For the new request a new Session will be created and the Session id will be sent to the client machine. Two different browser opened on the same machine will cause creation of two separate Session, one for each browser if they call the same web application. Though the browser Session comes to the end when user closes the browser however there is no way for the server to get if the information if the user has closed the browser so the Session is still alive at the server. If the server doesn’t get another request from the user for the time specified for Session timeout then the Session will be timed out and later will be cleaned up.

Where is it created
Session creation place is a big question for most of us. But it is simple that the Sessions are created at server, it takes up server resources and the Session ID is stored as a small piece in Cookies at client end. So it will remove it from user’s machine when the particular browser is closed. And from server for general Session it will destroy when user closes the browser and session reaches the timed out state. But if developer specifically creates Ses

PeterNZ

Date:: Jul 24, 2007

Time:: 14:59

Hello Prajith,

that's an interesting web page where you copied this from. If someone wants to have a look:
http://www.dotnetspider.com/kb/Article19...

Cheers

Peter

bc030400030

Date:: Aug 03, 2007

Time:: 23:16

thnks

admin

Date:: Aug 24, 2007

Time:: 23:38

bc030400030, did you get your question solved?

If you did then please close this question and distribute the points. If you found the solution on your own, we would be very happy if you could explain it here for the sake other users having the same problem.

If you didn't get a solution to your problem, please leave a comment here to let the experts know that you're still looking for an answer.

Thanks,
The Quomon Admin Team

mdhameed09

Date:: Oct 31, 2008

Time:: 23:51

hi i want to give session timeout unitll the user close the browser by defalut the session will be expire after 20 min but in my case the user can expire in 5 or 60 or 500 min
how to create that ....

please send me the link or answer it very urgent

admin

Date:: Nov 01, 2008

Time:: 01:14

Hi mdhameed09,
You should ask this question as a new one, this will make it easier for the experts to see it and respond quickly to you.

Rahul

Date:: Apr 14, 2009

Time:: 08:06

u can use session("session_name")="value assigned to it"
u can use the session in this manner

admin

Date:: May 06, 2009

Time:: 10:35

The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.

The Quomon Team

ya_ocp2007

Date:: Aug 02, 2011

Time:: 06:37

if i understand you yr question about session state
enter this page i hope find yr solution
http://msdn.microsoft.com/en-us/library/...

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es