tags:

views:

14

answers:

0

I have faced a strange and very peculiar situation while storing a session variable in a controller. A simple if-else condition has not been working. I checked to see if there were any threaded applications accessing the webservice, any extra instance which was consuming the requests. None.

And just for a simple explanation, below is what the code looks like.

if (Session["sessionVar"] == null) 
     Session["sessionVar"] = myObject;
else
    myObject = Session["sessionVar"];

As I watched in debug mode, the program hit the if, stored the session variable and then hit else as well and assigned myObject the old session variable. All in one flow and go. If I have my programming conventions right, once if is hit, else should be skipped right? Then why does it enter else after hitting if ???

MyObject is created once during a session and on page refreshes I am trying to use the old session object. But the if-else condition flowing all together is causing a inconsistent state which is of no use.

What could be the problem?