RemoveFromSession is used to remove existing session variables from the user’s session. If this service is used to remove a varaible which does not exist yet or existed in a previous session, the service still returns “True” since the end result is the same as it having existed and being successfully removed.
Storing information in session variables can be useful if you want a certain value to be accessed after a few pages, but won’t be carrying that information forward via query strings.
Session variables are special variables that exist only while the user's session with your application is active. Session variables are specific to each visitor to your site. They are used to store user-specific information that needs to be accessed by multiple pages in a web application. Unlike a cookie, the information is not stored on the users computer.
The default behavior is to store the session variables in the memory space of the Internet Information Services (IIS) worker process. If you are using this default in-memory session management, the session variables will be cleared when worker process recycles. IIS Worker Process Recycling is the process whereby IIS kills off the child processes that it spawns to handle incoming requests and starts clean copies of them. Over time, problems could arise in the processing (memory leaks in the application code, undisposed resources, etc.) that IIS wants to clean up without having to shutdown the server. So it will periodically tell the worker process to die off, and spawn a new one.
The user’s IIS session ends when the worker process is killed. This happens on the session timeout (timeout set in IIS on application pool) or when closing the browser. After this point the session variables saved previously will be lost. If you need the variables to be around for longer than this, consider using cookies.
RemoveFromSession is not often used, because if you want to override the value, it does not require a remove first. You simply need to run another AddToSession service with the new vaue and same name.