ASP.NET SessionState timeout - asp.net

I use ASP.NET website on IIS7 where in web.config I have:
<sessionState mode="InProc" timeout="20"></sessionState>
But session doesn't keep 20 minutes, it works very strange, sometimes it expires in 1 minute or less, sometimes just redirect to other page. I need use mode="InProc".
Who can help me, what is wrong and how to resolve this problem?
Thanks!

If you have an application that is throwing unhandled exceptions, the application could recycle. Or, it could recycle because of memory pressure or even just from the wrong settings in IIS. This would cause you to lose session. You can put some logging code in the Application_End Eventhandler in global.asax to check for this condition.

Application Pool Recycling? (IIS setting).
Anyway, you can detect and handle the timeout in the global.asax (session_end), if that helps.

Related

To Increase Request Timeout only on particular Web Page

Is it possible to increase the request timeout for just the one particular web page? I am working on ASP.Net 4.0 and I need one particular page to have a longer request timeout, since it is responsible for initiating a long running process. Thanks.
Use Web.config:
<location path="Page.aspx">
<system.web>
<httpRuntime executionTimeout="180"/>
</system.web>
</location>
This is an old thread, but it should be emphasized that updating the executionTimeout of a page or the entire machine must also be accompanied by the compilation debug flag being set to "false", otherwise the timeout element is ignored.
Also, depending on whether or not you are using AJAX update panels, you may also have to look at the AsycPostBackTimeout flag on the ScriptManager itself - depends on how your timeout is manifesting itself. Ajax post back timeouts will be seen as error messages logged to the Javascript Console and tend to manifest themselves as ajax operations "dying on the vine" depending on how you are handling things.
The debug="false" bit is probably what is afflicting the gentleman above who was having issues on his Amazon Server, but not locally.
Some googling will also reveal that some folks have noticed that localhost handles things differently as well, so you may need to experiment around that.

asp.net session expires before the time limit

I Have asp.net application in which i am using open id of google for authentication and i used to display the email address returned from google on a label control like this in vb.net
lblemail.Text = Session("U_EMAIL").ToString()
Problem is that after some time this error displays and i have to re login and then page works normaly error is Obeject Reference is not Set To an Instance of Object on this line
lblemail.Text = Session("U_EMAIL").ToString()
I tried to increase the limit of session in web.config like
<system.web>
<sessionState mode="InProc" cookieless="false" regenerateExpiredSessionId ="true" timeout="129600" />
But Still No Difference because when page loads and after some time the above error displayed please help me to remove this error
There maybe is other things that happens to your website. Is it in dev? You maybe restart the webserver. The Application pool get's restarted if you change many files in your websites folder, or if you touch anything in the bin directory.

session time out

I use asp.net and set the session timeout using
Session.Timeout = 1440;
but the session timed out, is there anything shall I fix or adjust in iis 7 and 6
Best regards
This may work
<configuration>
<sessionstate
mode="inproc"
cookieless="false"
timeout="1440"
/>
</configuration>
If the sessionstate timeout in the web config is not working check for memory leaks in your application. I had the same problem in a legacy application I inherited. After a lot if digging I found some custom server controls with static variables and static objects referenced by multiple pages and other objects. This caused the application to never release resources. Eventually IIS recycles the pool when it runs out of memory. When the pool is recycled all sessions will be unloaded from memory also.

Simulate Validation of viewstate MAC failed at home

In my webSite , if i do postback after 5 minuts I get this error:
Validation of viewstate MAC failed...
I realized it was probably because it's idle-timeout of the application pool
My site sits on plesk server.
My site is not use server farm, just one server.
I try to simulate the error on my computer and I can not.
I have windows 7 with iis7, i changed the application pool idle timeout to 1 minute
and submit a postback after 2 minute, but i did not get any error, the page refresh ok.
and it is the same page like i have in the real server.
so, how can I Simulate that error at home on my pc?
thx
micha
In your web.config, try adding the following:
<system.web>
<pages enableViewStateMac="false" />
</system.web>

IIS Request Timeout on long ASP.NET operation

I am experiencing a request timeout from IIS when I run a long operation. Behind the scene my ASP.NET application is processing data, but the number of records being processed is large, and thus the operation is taking a long time.
However, I think IIS times out the session. Is this a problem with IIS or ASP.NET session?
If you want to extend the amount of time permitted for an ASP.NET script to execute then increase the Server.ScriptTimeout value. The default is 90 seconds for .NET 1.x and 110 seconds for .NET 2.0 and later.
For example:
// Increase script timeout for current page to five minutes
Server.ScriptTimeout = 300;
This value can also be configured in your web.config file in the httpRuntime configuration element:
<!-- Increase script timeout to five minutes -->
<httpRuntime executionTimeout="300"
... other configuration attributes ...
/>
Please note according to the MSDN documentation:
"This time-out applies only if the debug attribute in the compilation
element is False. Therefore, if the debug attribute is True, you do
not have to set this attribute to a large value in order to avoid
application shutdown while you are debugging."
If you've already done this but are finding that your session is expiring then increase the
ASP.NET HttpSessionState.Timeout value:
For example:
// Increase session timeout to thirty minutes
Session.Timeout = 30;
This value can also be configured in your web.config file in the sessionState configuration element:
<configuration>
<system.web>
<sessionState
mode="InProc"
cookieless="true"
timeout="30" />
</system.web>
</configuration>
If your script is taking several minutes to execute and there are many concurrent users then consider changing the page to an Asynchronous Page. This will increase the scalability of your application.
The other alternative, if you have administrator access to the server, is to consider this long running operation as a candidate for implementing as a scheduled task or a windows service.
Great and exhaustive answerby #Kev!
Since I did long processing only in one admin page in a WebForms application I used the code option. But to allow a temporary quick fix on production I used the config version in a <location> tag in web.config. This way my admin/processing page got enough time, while pages for end users and such kept their old time out behaviour.
Below I gave the config for you Googlers needing the same quick fix. You should ofcourse use other values than my '4 hour' example, but DO note that the session timeOut is in minutes, while the request executionTimeout is in seconds!
And - since it's 2015 already - for a NON- quickfix you should use .Net 4.5's async/await now if at all possible, instead of the .NET 2.0's ASYNC page that was state of the art when KEV answered in 2010 :).
<configuration>
...
<compilation debug="false" ...>
... other stuff ..
<location path="~/Admin/SomePage.aspx">
<system.web>
<sessionState timeout="240" />
<httpRuntime executionTimeout="14400" />
</system.web>
</location>
...
</configuration>
I'm posting this here, because I've spent like 3 and 4 hours on it, and I've only found answers like those one above, that say do add the executionTime, but it doesn't solve the problem in the case that you're using ASP .NET Core. For it, this would work:
At web.config file, add the requestTimeout attribute at aspNetCore node.
<system.webServer>
<aspNetCore requestTimeout="00:10:00" ... (other configs goes here) />
</system.webServer>
In this example, I'm setting the value for 10 minutes.
Reference: https://learn.microsoft.com/en-us/aspnet/core/hosting/aspnet-core-module#configuring-the-asp-net-core-module
Remove ~ character in location
so
path="~/Admin/SomePage.aspx"
becomes
path="Admin/SomePage.aspx"

Resources