From someone else's handcuffs. Experience in the use of the session _ Practical skills

Source: Internet
Author: User
Tags httpcontext session id sessions
Q: When the page is frameset, it is found that the SessionID that displays the page in each frame is not the same on the first request, why?
A: The reason is that your frameset is placed on an HTM page rather than an ASPX page.
In general, if frameset is an ASPX page, when you request a page, it first sends the request to the Web server, the SessionID has been obtained, and then the browser will request the other pages in the frame, so that all the pages SessionID is the same, Is the SessionID of the frameset page.
However, if you use an HTML page to do frameset page, the first request will be an HTML page, when the page returned from the server is not any session generated, and then the browser will request the page inside the frame, so that these pages will produce their own sessionid, So in this case, this problem arises. When you refresh the page, the SessionID will be the same and the SessionID of the last request page.

Q: Can you save sessions for different applications on different databases on the same SQL Server server?
Answer: Yes, please refer to:
Fix:using one SQL database for all applications to SQL Server session state may cause a bottleneck
http://support.microsoft.com/default.aspx?scid=kb;en-us;836680

Q: In Session_End is it possible for me to get valid HttpSessionState and HttpContext objects?
A: You can get the HttpSessionState object in this method, you can access it directly using the session. However, the HttpContext object cannot be obtained because the event is not associated with any request, so there is no context object.

Q: When I set EnableSessionState to "ReadOnly", but I can still modify the session value in InProc mode, why?
A: Even if EnableSessionState is marked as ReadOnly, the user can still edit the session in InProc mode. The only difference is that the session will not be locked during the request process.

Q: What happens when the session is set to cookieless?
A: When you set the cookieless to true, there are mainly the following constraints:
1, can not use the absolute link in the page
2, in the application in addition to HTTP and HTTPS switch between the need to complete a number of other steps.
If you send a link to another person, the URL will contain the session ID information, so two people will be common to a session.

Q: Does the session provide a locking mechanism in order to access the state value of the session sequentially?
A: Session implementation of the Reader/writer lock mechanism:
When the page has writable functionality to the session (that is, the page has the <%@ page enablesessionstate= "True"%> tag), the session holding a write lock is held until the session on which the page is requested to complete.
When the page has read-only functionality to the session (that is, the page has the <%@ page enablesessionstate= "ReadOnly"%> tag), it knows that the session that requested the page to complete holds a read lock.
Read locks block A write lock, read locks do not block read locks, and write locks block all read and write locks. This is why the same page in both frames writes the same session, and one of them waits for the other (the slightly faster one) to finish before it begins to write.

Q: If cookieless is used, how do I redirect from an HTTP page to HTTPS?
A: Please try the following methods:
String Originalurl = "/fxtest3/sub/foo2.aspx";
String Modifiedurl = "Https://localhost" + response.applyapppathmodifier (Originalurl);
Response.Redirect (Modifiedurl);

Q: What type of object can be saved in the session?
A: This relies on the use of Session mode, which is used in-process (INPROC) sessions so that you can easily save any objects. If you use a inproc pattern, you can only save objects that are serializable and deserialized, and you cannot save to a session in this mode (not InProc) if the object you are saving is not serializable.

Q: Why is the sessionid of each request different?
A: The problem may not be caused by saving any information in the session, that is, no session is used anywhere in the program. SessionID will always be relevant to the browser when the information is saved in the session, and the SessionID will not change at this time.

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.