I am using MVC5. at every 15 minute or before it session is expired
below is the code that i have added in web.config file
authentication mode="None"
sessionState mode="InProc" timeout="20"
Please Help me.
Thank you
InProc session storage is in-memory and tied to the process. In other words, it's volatile: both because the memory can be reclaimed and the process can be killed. In particular the App Pool is set to recycle periodically by default and can also crash, or IIS or the server itself could be restarted. All of these will destroy any active sessions.
InProc is really only viable in development, to save you from having to set up an actual session store, just to play with some code. In production, you should always be using something else, like SQL Server or Redis. Even in development, it's important to realize that, again, since it's tied to the process, doing something like stopping and restarting debugging will kill the IIS Express process and thus your session state.
You can increase the session timeout by adding below lines in web.config
timeout in Minutes
<sessionState timeout="120">
</sessionState>
If you're hosting your website in IIS and you've not made any request to your website for 15 minutes, then it's likely the app pool has been recycled. It means that any data that was stored in memory (like the session state as you specified mode="InProc") has been lost and a new thread was created when accessing the website after 15 minutes. You would easily notice if this is the case as the app pool start up time can take 10 to 30 seconds - which explains why the first request take so long to render and subsequent requests are much faster.
If this is happening on your local machine, any re-compilation of your code would have the same effect.
Another possibility is that you are behind a load balancer and that the second request doesn't go to the same physical server which served the first request. (obviously, the second server has no knowledge of what's in memory on the first server)
For those reasons, it's best to avoid mode="InProc". You wouldn't want to use mode="InProc" in production, and it's better to stick with the same settings in Development, so you can see any issues early.
I have a similar setup
<sessionState mode="InProc" cookieless="false" timeout="20" />
setting it to 20 minutes.
Related
So started working for a company on my first production job as a developer where I am writing a MVC web application. Told for certain data we didn't want to have any persistent storage, so just keep it in session. I just finished setting up the production environment so that we can do automatic deployment to the servers.
I do so in a rolling deployment manner. Drain connections from a machine, take it down, deploy new code, bring it back up then do the next machine.
From my first test this seems to kill the session data, which was what I was worried about. Is there a way within IIS to transfer session data when a user switches machines, or do I need some sort of shared file storage to recover in the case the user has to be removed from a machine to load new code onto it.
I am using Big-Ip for my load balancer that does the draining and I don't think it necessarily knows anything about IIS. First experience with the complexities of production level deployment with no downtime requirements. I imagine, I'll need a file storage backup to 'recover' if necessary. Just want to make sure I'm not missing something.
Best practice for a server farm (even if it's just two) is to NOT use session for anything. Apart from the fact that Session can cause performance problems (Session access is serialized and can slow performance as your load increases), Session is also considered transient storage, and can literally disappear at any time. When the IIS app pool is restarted, session is lost (either intentionally or unintentionally). Also, IIS can dump sessions even before they expire if it starts running low on resources.
Session is basically unpredictable, and unreliable. Anything you put in session should be rebuildable from your app if it finds the session data is gone.
Of course, this is for in-proc session. You can use a state server tied to a database, but this too will affect performance. Especially if you make heavy use of session.
In general, design your apps to NOT use session, unless it's for trivial things that can easily be recreated if they are no longer found.
I have multiple servers (2012 R2 with IIS 8.5) that have shared configuration, shared vanity URL (f5 load balanced), and host several different applications. One of the applications (an ASP.NET MVC web app) is rarely used (maybe once or twice a week) but when it needs to be used, it needs to load quickly.
I've set the AppPool to have a Start Mode of "AlwaysRunning", and a Recycling -> Regular Time Interval to 0, but it seems like every time I hit the app, it takes forever to load (like 10-20 seconds) but subsequent page requests happen instantly.
Is there another setting that I need to set to keep the app warmed up? The app has Kerberos Authentication and access is limited to one security group (that I'm not even a member of), so I can't use external PowerShell scripts to manually keep it warm.
You can check to see if the application pool is running before you hit the app.
If you click on your server name in IIS then click on "Worker Processes" you'll see all the Process ID's of the different application pools and that state.
This way you can confirm the app pool is running, before you access the application. This will help you narrow down where the problem exists.
1) Is the app pool running?
2) Is my app loaded in my app pool?
If 1 checks out, then move on to step 2 and check to see if the libraries of that application is loaded up in that Process ID.
Check your event log for application pool failures.
If you have some asynchronous initialisation/maintenance task which is started in parallel with the request or with some delay and subsequently fails, it can make the request (and some afterward) succeed but kill the application pool shortly after. This would exhibit these exact symptoms.
I've got a site which has an export feature. This feature can export parts of the database up to a full database export. This has been optimized a lot but still requires some 90-180 seconds to finish. Debugging and time outs aren't an issue, but live I receive a 504 gateway time out error after about 90 secs. I am guessing that IIS gets tired of waiting for the backend to respond and returns a 504. Is there any way to specify a longer time out, e.g. 5 minutes?
I've got an old executionTimeout setting set to 3600 which doesn't seem to do much any more (I believe it's an IIS <7 setting).
I've also tried this suggestion form another Stackoverflow question:
<configuration>
<system.applicationHost>
<webLimits connectionTimeout="00:01:00"
dynamicIdleThreshold="150"
headerWaitTimeout="00:00:30"
minBytesPerSecond="500"/>
</system.applicationHost>
</configuration>
The above doesn't work, the config file is broken. Is the above supposed to work?
Main question: how/can I increase waiting time in IIS to avoid 504s?
This wasn't an IIS issue. I believe the old way of providing a timeout worked. We've got a reverse proxy with a short timeout, this was changed to a longer timeout which effectively resolved the issue.
I have Overlapping Recycling configured for my ASP.NET MVC site.
As I understand it (from this SO question), if I Recycle the Application Pool, this will spin up a new w3wp.exe process to take up the load of the one being recycled, and only when the new process is initialised and taking the load, will the old process be shut down. And if I stop/start the Application Pool, it does an immediate kill without letting the process quit gracefully or letting a replacement process spin up first.
Question: when I edit my Web.config file, it will restart the associated IIS Application Pool. Is this going to trigger the nice overlapping recycling behaviour, or the brutal stop/start behaviour?
I'm trying to decide if I need to take a server out of a load-balanced farm and do a drain-stop on the server traffic in order to edit configuration settings.
I decided to use science. I ran an experiment with my server under a load-testing tool, where I repeatedly edited and saved my Web.config file while requests were poured in.
No requests were dropped when changes were saved to the Web.config file.
I did observe a short spike in CPU activity while the new settings were loaded, but really barely noticeable at all.
I was able to prove that the settings were getting loaded by making the Web.config file badly formatted and saving it. This immediately caused requests to start failing.
What surprised me is that the process id did not change with a Web.config edit. My understanding of the IIS Overlapping Recycle was for IIS to start a new w3wp.exe process, and then wind down the old one. Which would have meant a different process id. So I don't think Overlapping Recycle is kicking in here.
Since the process id is the same, then I reason that its a totally separate mechanism which loads/unloads the AppDomain. This seems to be supported by this document, the relevant bit is reproduced below:
Configuration Changes Cause a Restart of the Application Domain
Changes to configuration settings in Web.config files indirectly cause
the application domain to restart. This behavior occurs by design. You
can optionally use the configSource attribute to reference external
configuration files that do not cause a restart when a change is made.
For more information, see configSource in General Attributes Inherited
by Section Elements.
TLDR
Neither Overlapping Recycle, or the brutal stop/start behaviour are caused by a Web.config edit. The AppDomain is re-loaded with the new settings without interruption to request processing.
http://msdn.microsoft.com/en-us/library/ackhksh7.aspx
Editing (or touching) the web.config will not trigger a 'nice overlapping recycling'.
As described above, the request process will not been 'interrupted' but new incoming requests have to wait until the new worker process has finished its initialization. So depending on the time for initialization, there will be a noticeable break.
I noticed that on a WCF-Service Application hosted in IIS7.5 where I implemented IProcessHostPreloadClient to do some time expensive preload stuff.
On the other hand a 'recycle' by clicking the app-pool's context menu item at the IIS Manager will do the nice overlapping: New incoming requests are processed by the old worker process as long as the new one works on the preload method.
I have a project in asp.net mvc, my hosting is using IIS6, and the first request after the website sit's idle is very slow.
I looked at, http://forums.asp.net/t/1418959.aspx and asked the hosting for this settings.
They say that the actual settings are:
"The pool is set with Idle Timeout disabled, Rapid-fail enabled and with a single worker process."
But still slow at the first request. Do you have any other clues?
Thanks in advance,
Alfredo
You are probably a victim of worker process recycling. Ask your host how often the worker processes are recyled.
When a worker process is recycled, it has to recompile and restart the entire web application, and that's what causes the slowdown.
This is natural.
IIS is often configured to shut down the website if it's a certain age or if there hasn't been a request in awhile. Your website has to be loaded (and possibly compiled) when the first request comes after asp.net has been shut down by IIS.
The common solution is to precompile your website before publishing it to the server.
Just a guess, but perhaps you are caching some data, that needs to be refreshed after the site has been idle for some time ?
If this is not the case, then my guess would be that the worker process has been shut down for some reason (it could be for some other reason than the idle timeout in IIS). If you need to check whether this might be the case, you could add some code to the Application_Start event that logs the startup event to a file or whatever logging you have in place. After some time in operation, you can examine the logs and see, how many Application_Start events has occured.