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