tags:

views:

51

answers:

4

I have been using session variables in my asp.net application for passing the next property:

[DefaultValue(true)]
public bool IsModificationMode
{
    get
    {
        return (bool)Session["ModificationMode"];
    }
    set { Session["ModificationMode"] = value; }
}

In the PageLoad, I set it's value.

Now after the Postback, I am losing it's value having a a NullReferenceException

+1  A: 

The issue is may be because of, 1. You are either clearing the session somewhere in the code, or 2.your application pool is being recycled causing you to lose you session information. check your code, check the eventvwr for application recycle messages.

stacknewbee
+1  A: 

Is this a web farm, more than one server? You might need SQL persistence of session so it spans servers. Is your application recycling for any reason between postbacks? In-memory session state will be lost. How long between postbacks? Is your session timing out (I think it defaults to 20 min)? Are you sure you're actually setting the value? Don't laugh - I've done it.

And, are you absolutely positively sure you NEED to use session state? Could view-state work?

n8wrl
A: 

I upvoted @stacknewbee because I agree with his idea of the application pool self-recycling. As a solution, try uncoupling the session state from the w3wp.exe process by changing the web.config entry from InProc to StateServer:

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" timeout="30"/>

Keep in mind that the server service ASP.Net State Server must be started.

Joel Etherton
A: 

Thanks for all your replies It was the entry [SessionState] where i missed it in my Web.config:

abdelrahman ELGAMAL
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" timeout="30"/>
abdelrahman ELGAMAL