Answered by:
Session in Global.asax..plz help

Question
-
User-1604169926 posted
Hello everyone, plz tell me how to retrive specific session in global.asax file..
actually i am making chat application and i want to change online/offline status of particular user..
whenever user login in my site, a session named "SUsername" created..now using this session i want to set online/offline status in my user database for that particular user..So i need to retrieve session in session_start and session_end event in global.asax..but when i try to retrieve it , I am getting NullReferenceException(Object reference not set to an instance of an object)
Please help me how to do this..or if this is not possible then tell me other way how to perform the same function..my condition is that whenever user closes its window(without logging out), its status should be set to offline.
Monday, July 25, 2011 11:19 AM
Answers
-
User-578657687 posted
Hi,
I am getting NullReferenceException(Object reference not set to an instance of an object)That means the Session["SUsername"] is null, so you will get "NullReferenceException" when you try to retrieve the Session variable.
whenever user login in my site, a session named "SUsername" createdThe session named SUsername has not been crreate when the Session starts. In other word, you do not really get it. I noticed this sentence "whenever user login in my site, a session named "SUsername" created", As a result, you can create session["SUsername"] and meanwhile set online status when the user sign in your site. Now you can retrieve the session variable from Session_End event.
But there is a key point you need to regard: The Session_Event will not be fired when the user close the window using "X" of browser. To solve this issue you may check the link below and then re-design your logic:
http://forums.asp.net/t/1251789.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 29, 2011 5:31 AM -
User-1768369891 posted
check this link:
http://forums.asp.net/t/1297917.aspx/1?Using+Session+in+Global+asax
http://forums.asp.net/t/1376102.aspx/1?Global+asax+file+sessions+
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 29, 2011 6:31 AM
All replies
-
User-718146471 posted
Can you show us the code you are using to grab the session variable? I would think from Code Behind you'd do it something like this (paraphrasing the code of course :) )
if (Session["SUsername"] == null) { Status.value = "offline" } else { Status.value = "online" }
Monday, July 25, 2011 11:38 AM -
User-1604169926 posted
Hello bbCompent,
I want to just retrieve session "SUsername" in global.asax file so that i can set value of Online field in my user db..I dont want to check whether its null or not, cuz session_end in global.asax doin it for me already..
I want to just set my user's status to offline when session_end occurs..
Monday, July 25, 2011 12:36 PM -
User-718146471 posted
The problem you are going to run into most likely is when the user closes the window, the session ends and with it all the variables go too. If you are using a database, you could on session end write into a table the user is offline. When they log on, they are then written as online.
Monday, July 25, 2011 12:56 PM -
User-578657687 posted
Hi,
I am getting NullReferenceException(Object reference not set to an instance of an object)That means the Session["SUsername"] is null, so you will get "NullReferenceException" when you try to retrieve the Session variable.
whenever user login in my site, a session named "SUsername" createdThe session named SUsername has not been crreate when the Session starts. In other word, you do not really get it. I noticed this sentence "whenever user login in my site, a session named "SUsername" created", As a result, you can create session["SUsername"] and meanwhile set online status when the user sign in your site. Now you can retrieve the session variable from Session_End event.
But there is a key point you need to regard: The Session_Event will not be fired when the user close the window using "X" of browser. To solve this issue you may check the link below and then re-design your logic:
http://forums.asp.net/t/1251789.aspx
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 29, 2011 5:31 AM -
User582086724 posted
hi..refer the below links
http://vbdotnetaddict.blogspot.com/2011/01/avoid-multiple-user-to-login-at-same.html
Friday, July 29, 2011 6:25 AM -
User-1768369891 posted
check this link:
http://forums.asp.net/t/1297917.aspx/1?Using+Session+in+Global+asax
http://forums.asp.net/t/1376102.aspx/1?Global+asax+file+sessions+
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, July 29, 2011 6:31 AM