Several questions about session in ASP. NET

Source: Internet
Author: User
1) for value-type variables, the session stores the copy session of the Value Type ["_ test0"] = 1;
Int I = (INT) session ["_ test0"] + 1;
Int J = (INT) session ["_ test0"];

Result I = 2, j = 1
2) For new variables of the reference class, the session stores the reference cdacommon CDA = new cdacommon ();
Session ["_ test"] = Cda. getdataset ("select top 1 * From tb_customer ");
Dataset DS = (Dataset) session ["_ test"];
Dataset ds2 = (Dataset) session ["_ test"];
DS. Tables [0]. Rows [0] [0] = "9999 ";

Result Ds. Tables [0]. Rows [0] [0] = "9999" ds2.tables [0]. Rows [0] [0] = "9999 ";
3) after the new browser window is started, a new session is started to trigger the global session_start call. The new session is not started from the browser window opened in the first browser window. After the session expires, the execution page commit will also trigger session_start, which is equivalent to a new session.
4) for Web Services, each method call starts a session. You can use the following method to make multiple calls in the same session cwssyscfg cwscfg = new cwssyscfg ();
Cwscfg. cookiecontainer = new system. net. cookiecontainer ();

Cwssyscfg is a Web service class. The cookiecontainer attribute is set for the proxy class by the web service. As long as the cookiecontainer attribute of multiple proxies is the same value, the Web Service is called in the same session. It can be implemented in singleton mode.
5) as long as the page has a submitted activity, all items of the session will be maintained, and the session will become invalid if the page does not have any submitted activity within 20 minutes (default configuration. Multiple Data items stored in the session are invalid as a whole.
6) if a non-serialized class such as dataview is saved in the session, it cannot be used in the mode of saving the session with sqlserver. To check whether a class is serialized, you need to check whether the class is marked with [serializable.

7) the purge of sesson is not too clear. If I keep a relatively large datasetin session, the memory occupied by aspnet_wp.exe will be very large. If I quit the page using this dataset, I want to release this session, and I will use the session. clear () or dataset. clear () cannot reduce memory usage. Even if the session expires, the memory has not been downgraded. It is confusing. Who can explain it to me in detail.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.