Friday, September 26, 2008

Ways to solve session expired problem

1)
setting time limit in the web.config file

< mode="InProc" timeout="20" cookieless="false" stateconnectionstring="tcpip=127.0.0.1:42424" sqlconnectionstring="data source=127.0.0.1;Trusted_Connection=yes" >

..Here the timeout "20" is mins

2)
One possible explaination is that you are using .Net Server 2003 and your IIS Application Pool is configured to recycle the worker process after 10 minutes.
When the asp worker process is recycled, the session state is dropped and the user is forced to log in again.

3)
Well, we solve the problem, we was hosting our web application at web garden architicture server machines (multi server machines), at that time our session mode was InProcess so, no unexpected logged out was happen in our local machines but when we host it to server unexpected logged out appears. So, wab garden server machines seems to distribute our worker processes so Session mode shall be in StateServer mode.

As i read, and for the reason that Worker process is distributed, you cannot use InProcess mode.
therefore, you should set session mode to stateserver, and make sure that your Session object is Serialized and any other objects that it used shall not be serialized.

another thing make sure that you don't miss your connections (leaking of connections) by disposing each connection opened, since any exception appeared within uses of connection will not close it, it will still opened so try to dispose connections always, even if you close it..

4)
Under ASP.NET , the timeout error message reads as follows:
Exception Details: System.Web.HttpException: Request timed out.

In .NET, there is an additional setting for this. The default script timeout is set to 90 seconds by the httpRuntime section of the machine.config file. You can change this setting to affect all applications on your site, or you can override the settings in your application-specific web.config as follows:

< system.web >
< httpRuntime executiontimeout="900" >
< /system.web >

The .NET config files are usually stored in the folder C:\Windows\Microsoft.NET\Framework\[version]\Config where [version] is the version of the .NET Framework such as v1.1.4322. You may need to restart IIS for such changes to take effect.


5)
You have to set the session timeout in default website also.
Do the following. go to IIS Manager, right click on the virtual directory and choose properties.
Now go to virtual directory tab, click Configuration button. now a dialog box will appear.
choose AppOptions tab. Set the session timeout that u need. This will solve the problem.
If you are agin getting the same problem then set the same thing for Default WebSite also.


6)
1.) I first noticed session ending during the redirect operation. Next most important was code executing after the redirect. I found when I use redirect, any coding following the redirect statement will execute and may cause errors.

2.) Any page or application errors may cause a session end. I set up an email message in the page catch statement and application level to track down bad coding on my part.

3.) Configuration of HttpRuntime help too, I found certain threading issues. This is my current webconfig statement:
< httpruntime executiontimeout="250" minfreethreads="12" minlocalrequestfreethreads="12" >

4.) If in production turn off debug, your application will running harder if turn on.
< compilation debug="false" defaultlanguage="vb" >


7)
use server.transfer () instead of response.redirect()...


8)
Try using sessionstate mode=stateserver, because the worker process my recycle any session in InProc will be deleted from memory along with the recycle.
The stateserver do not recycle with the worker processing and will allow for longer session times.


9)
It is IIS setting that reset ideal process after few mins if not used to refresh memory for IIS service.
We could allow your domain name the maximum time before service restart and that will help to resolve your issue


10)
If changing the timeout session in IIS do not work, you have 2 other solutions.
The first one is to remove the check of the session timeout in IIS, then the timeout will be read from the webconfig.
The second solution is to add the following code in the web.config file under
< system.web >
< sessionstate mode="InProc" timeout="240" cookieless="false" >


11)
I also faced the same problem of session timeout not working properly even changing the web config property.
Later when i debuged the code i found out that in FormsAuthenticationTicket I was setting the cookie expiration time out as something else than my session value on the web.config.This value I changed in my login form to solve the problem
<<<<< datetime.now.addminutes(60) >>>>> this setting i changed as per the web.config setting.

FormsAuthenticationTicket authTicket =
new FormsAuthenticationTicket(1, // version
txtUserName.Text,
DateTime.Now,
DateTime.Now.AddMinutes(60),
false,@"\");

No comments: