InProc Session Mode:-
- This is the default session mode in ASP.NET.
- Its stores session information in the current Application Domain.
- This is the best session mode for web application performance.
- But the main disadvantage is that, it will lose data if we restart the server.
Overview of InProc session mode
As I have already discussed, in InProc mode, session data will be stored on the current application domain. So it is easily and quickly available.
InProc session mode stores its session data in a memory object on the application domain. This is handled by a worker process in the application pool. So if we restart the server, we will lose the session data. If the client request for data, the state provider read the data from an in-memory object and returns it to the client. In web.config, we have to mention the session mode and also set the timeout.
The above session timeout setting keeps the session alive for 30 minute. This is configurable from the code-behind too.
Session.TimeOut=30;
When should we use the InProc session mode
It is the default session mode. It can be very helpful for a small web site and where the number of users is very less. We should avoid InProc in a Web Garden scenario.
Advantages:
- It store session data in a memory object of the current application domain. So accessing data is very fast and data is easily available.
- There is not requirement of serialization to store data in InProc session mode.
- Implementation is very easy, similar to using the ViewState.
Disadvantages:
Although InProc session is the fastest, common, and default mechanism, it has a lot of limitations:
- If the worker process or application domain is recycled, all session data will be lost.
- Though it is the fastest, more session data and more users can affect performance, because of memory usage.
- We can't use it in web garden scenarios.
- This session mode is not suitable for web farm scenarios.
As per the above discussion, we can conclude that InProc is a very fast session storing mechanism but suitable only for small web applications. InProc session data will get lost if we restart the server, or if the application domain is recycled. It is also not suitable for Web Farm and Web Garden scenarios.