Last post Apr 18, 2019 07:23 AM by PatriceSc
Apr 17, 2019 11:35 AMfirstname.lastname@example.org|LINK
i use session and pass that session value to all the page why sometimes returns null
Apr 17, 2019 11:48 AM|PatriceSc|LINK
There is not much to say. You should first see what happens exactly.
My first move would be to see if a new Session started (checking the ID or Session_Start in global.asax). You could also see if Application_Start happened to see if the app restarted causing session data to be lost.
Apr 17, 2019 12:23 PMemail@example.com|LINK
how can i check session_start in global.asax
Apr 17, 2019 12:59 PM|PatriceSc|LINK
BTW what means "sometimes" ? By default session state is kept for 20 minutes so if you wait for more than that and then refresh a page, it is actually the expected behavior.
If not, you could try something such as :
protected void Application_Start(object sender, EventArgs e)
protected void Session_Start(object sender, EventArgs e)
and then have a test page showing those values. If "Application_Start" just happened more likely you are doing something in your app that causes the application pool to be restarted causing the lose of all session data (for example creating files or folders
at wrong place).
Apr 17, 2019 02:02 PM|bruce (sqlwork.com)|LINK
also if you use inproc session or don't have fixed machine key, then session is lost on a recycle due to idle timeout or loading new code.
Apr 17, 2019 05:38 PM|markfitzme|LINK
Unless you use a persistence store or state server, session is always lost on an application pool recycle though as the memory is cleared.
Apr 17, 2019 07:13 PMfirstname.lastname@example.org|LINK
i added this machin code in the web.config but also the session will be lost
Apr 17, 2019 07:59 PM|mgebhard|LINK
The machine key only works if you are using a Session Server like SQL Server. The machine key has no affect on InProc Session as Session is stored in the app's memory as stated above.
Apr 17, 2019 08:01 PM|bruce (sqlwork.com)|LINK
if you set the machine key, and use sqlserver session manager, then sessions can last weeks. I often use a 2 week session.
Apr 18, 2019 07:23 AM|PatriceSc|LINK
Have you tried to see first what happens? For example it could be just a programming error for a particular session variable (I saw that once for someone).
This is why I would really check first if the application restarted or if the session restarted or if it just a particular value that is missing…. You have a single web server ?