Last post Jul 29, 2011 06:31 AM by navneetmitawa
Jul 25, 2011 11:19 AM|pratik_galoria|LINK
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.
Jul 25, 2011 11:38 AM|bbcompent1|LINK
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"
Status.value = "online"
Jul 25, 2011 12:36 PM|pratik_galoria|LINK
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..
Jul 25, 2011 12:56 PM|bbcompent1|LINK
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.
Jul 29, 2011 05:31 AM|Mamba Dai - MSFT|LINK
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" created
The 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:
Jul 29, 2011 06:25 AM|vijay_myl|LINK
hi..refer the below links
Jul 29, 2011 06:31 AM|navneetmitawa|LINK
check this link: