Asp.net project page opening slows down due to session Blocking

Source: Internet
Author: User

After an Asp.net project was launched in the previous year, most pages can be opened quickly under normal circumstances, but the processing speed of some pages is slow. It is strange that it takes a long time to access any other page before the page responds to a slow page.

After careful analysis and searching, we found that the culprit was caused by session blocking. By default, the session status is "writable" (enablesessionstate = "true"). That is, when a user opens any page, the session on this page will hold a write lock, write locks will block all read/write locks, so the corresponding session write locks will be released only after the page is processed. The write locks will be blocked when other pages are accessed before the page is released. The detailed description is as follows:

When the page has a writable function for the session (that is, the page has a <% @ page enablesessionstate = "true" %> flag), the session of the page holds a write lock until the request completes.
When the page has the read-only function for the session (that is, the page is marked with <% @ page enablesessionstate = "readonly" %>), the session of the page is read locked.
A read lock will block a write lock; A read lock will not block a read lock; A write lock will block all read/write locks.

 

Therefore, marking each page as <% @ page enablesessionstate = "readonly" %> solves this problem. You can also modify the default session Status of each page in Web. config:

<Pages validaterequest ="False"Enablesessionstate ="Readonly"> <Controls> <add tagprefix ="ASP"Namespace ="System. Web. UI"Assembly ="System. Web. Extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/> <Add tagprefix ="ASP"Namespace ="System. Web. UI. webcontrols"Assembly ="System. Web. Extensions, version = 3.5.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/> </Controls> </pages>

For some pages that do need to write session permissions (for example, operations with session ["AA"] = "BB"), you can set this page

<% @ Page enablesessionstate = "true" %>

 

 

References:

Http://www.anqn.com/aspx/2010-04-30/a09126048.shtml
Http://www.cnblogs.com/flier/archive/2004/08/07/30902.html

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.