Session Variable get set to null

Posted by Aatish under ASP.NET on 8/26/2009 | Views : 8563 | Status : [Member] | Replies : 3
when i set a session variable is set and used in one page and when i go to next page and use that session i am able to use it.
But when i go back to previous page by clicking on back button of browser.
And now if i use that session varible again it get set to null and if i try to use it, i get "Object reference not set to an instance of an object."

I am thinking of using Application_Error event of Global.asax file

Here can i check if error is of type "Object reference not set to an instance of an object."

and if error is of that type i will check all session variables if any of it is null and if yes i will redirect it to login page




Responses

Posted by: Lakhangarg on: 8/26/2009 [Member] [Moderator] Silver

Up
0
Down
Hi-
either increase the session timeout or write the same value in cookies and check while using it its null then read the value from cookie and set the session value..

Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/


Aatish, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumarsudu on: 8/26/2009 [Member] Starter

Up
0
Down
Hi,

You only want to move between two pages or between all the pages.

In either of the case you create a public class with get set properties.

Take a variable say sessionVariable, set this value in the first page and go to second page and retrieve the value in the second page, do the same process for the first page too.

Check in the first page whether the sessionVariable has been already assigned or not, if assigned then use that variable else assign it.

Hope this may help you

Thanks and Regards,
Kumar

Aatish, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 8/26/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day Aatish

Sessions are Very Easy to use and if you mistype the name if the session you declared Previously, you might get the Error that you are Getting now. I need you to give us more info on your problem.

Let us look at your Problem in details. when you have a Page to uses a Session like this

Session["MYVAR"] = "Hello";



and you navigate to another page , you will dafinately access this Variable

and if you Click Back and try to Navigate and again, the Session should not Give you an Error, because the Value and the Session get recreated again. if you put a Breakpoint, you will see that it goes again and recreate it. So Aatish please explain your situation.

Thank you for Posting at Dotnetfunda


Vuyiswa Maseko



Thank you for posting at Dotnetfunda
[Administrator]

Aatish, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response