Many people use Session variables to develop ASP (Active Server Pages). These variables are very similar to general-purpose variables in any programming language, and have the same advantages and disadvantages as general-purpose variables. Any command requires running time and storage space (even GOTO 's statements), and Session variables also require their own running time and storage space. Excessive use of Session variables will lead to code redundancy and increase server running costs. Here are some of my main views and experiences on using Session variables.
advantage
If you want to pass a variable between many Web pages, using Session variables can simplify the problem rather than passing the variable through QueryString.
To customize your WEb site, consider using Session variables. Every visitor to your site has a customization experience. Based on this, with the use of LDAP and such as MS Site Server, it is no longer necessary to put all the customization process into Session variables, and this customization depends on based on user preferences.
You can use the session variable directly whenever you want to use it without declaring it in advance. This method is close to the use of variables in VB. Once you're done using it, you don't have to think about releasing it, because it will be released automatically.
shortcoming
Session variables and cookies are of the same type. If a user sets the browser to be incompatible with any cookies, then the user cannot use this Session variable!
When a user visits a page, the running environment of each Session variable is automatically generated. These Session variables can remain for 20 minutes after the user leaves the page! (In fact, these variables persist until timeout. The length of timeout is set by the Web server administrator. Some sites have variables that persist for only 3 minutes, some for 10 minutes, and still others to the default value of 20 Minutes.) So, if you place larger objects (such as ADO recordsets, connections, etc.) in the Session, you will be in trouble! As the number of visits to the site increases, the server will not be able to operate properly!
Because creating Session variables is very arbitrary and can be called at any time without requiring developers to do precise processing, excessive use of session variables will lead to unreadable and difficult-to-maintain code.
Although you can use the session variable directly whenever you want to use it without declaring it beforehand, this method is close to the use of variables in VB. Once you're done using it, you don't have to think about releasing it, because it will be released automatically. But who would have thought there? What do the variables mean? None of this becomes very clear.
Summarize
Using Session variables has both advantages and disadvantages. In my personal opinion, it's best to use them sparingly, but using them in some places can really simplify web development. Whether to use Session variables depends entirely on personal needs. Regardless of whether to use them or not, you must consider their advantages and disadvantages in advance.