Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.70/5 (3 votes)
See more:
Respected All

Today i came with a confusion that when is session-start function in the global.asax called.

As we know that it is called when the session for new user is created.

My question is that

When there is needed to create session within the application for state management then what happens? it is called or not
How can one access the session created by asp.net for the user when he open the site.

Regards
TanzeelurRehman
Posted
Updated 8-Feb-18 1:47am

# Session_Start: Fired when a new user visits the application Website.
# Session_End: Fired when a user's session times out, ends, or theyleave the application Web site.

Or have a look on the link,-

http://www.techrepublic.com/article/working-with-the-aspnet-globalasax-file/5771721[^]

Hope this can help you.
 
Share this answer
 
Have a walk through this article, make sure you read "Life Cycle Events and the Global.asax file" section in the article: MSDN: ASP.NET Application Life Cycle Overview for IIS 5.0 and 6.0[^]
 
Share this answer
 
No matter session is required or not by default your ASP.NET web application will create session for data storage for a user.

A session starts when a user first time hits a web page. if he doesn't do any thing for specific duration the server disposes the session memory allocated for the user. The session expire duration is configured at server. Now when user again hits some page after his session expired the a new session is created again and assigned for user requests.

How can one access the session created by asp.net for the user when he open the site

I belive the one who is accessing session here is a web developer, well you dont have to do anything special, the .net framework provides Session class for all session related operations.

A web-site user cannot access the Session variables because it is a server side functionality. Imagine if the feature is exposed to web-user he can do blunders to your website.

Additionally if you want to add anything you can simply use Session["yourkeyName"] = "value for the key" it automatically creates the "yourkeyName" key if it doesn't exists and adds value to it and to get the value stored you simply write someVariable = Session{"yourKeyname"].

Hope the answer will clarify the doubts.

Thanks,
Hemant

Hi,

Well there are 2 ways of getting all active sessions it an easy way or a hard way:
1- easy way (i.e. use application level variable to store information)
http://stackoverflow.com/questions/1470334/list-all-active-asp-net-sessions[^]
http://stackoverflow.com/questions/1347007/how-can-i-view-everything-in-session-state-for-all-active-sessions[^]

2- hard way (i.e. use reflection)
http://weblogs.asp.net/imranbaloch/archive/2010/04/05/reading-all-users-session.aspx[^]

Hope it will help.
thanks,
Hemant
 
Share this answer
 
v2
Comments
TanzeelurRehman 5-May-11 4:31am    
Basically i had a problem in my website!
I have written code in the start and end functions of Global.asax
I am feeling that the active users are getting incremented and the code is not working when a user is leaving the website. so issue there, thats why i submitted the question i am a asp.net developer working for atleast 1 year. It was making me confuse. When a user visits asp.net make session for the user. I want to get total active sessions, if any functionality there please guide me
Regards
TanzeelurRehman
Hemant__Sharma 6-May-11 4:56am    
well i've impvoed current solution have a look at my answer.
Thanks,
Hemant

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900