1

Is there any setting or something that allows/disallows the same page to be loaded simultaneously in ASP.NET

Take the following piece of code.

protected void Page_Load(object sender, EventArgs e)
{
   if (Page.IsPostBack == false)
   {
      System.Threading.Thread.Sleep(20000);

      // etc.

Let's say, in Visual Studio, I set a breakpoint on the second line (if (Page.IsPostback...). I load the page on the first tab in my browser, the breakpoint is hit straight away. So I press continue. Then I load the same page in another tab in the browser. This time, the breakpoint doesn't get hit for 20 seconds (i.e. after the first load has completed).

I'd have thought that both tabs would load as separate threads or something in parallel.

Should it be? If so, what can I look out for that might be forcing this kind of serialised page load?

I've inherited this project so I can't really tell if it's something someone else turned on / off.

komodosp
  • 3,316
  • 2
  • 30
  • 59
  • 2
    they become individual requests to the IIS pipeline on the server. pages sitting on tabs may share a session. if you use the session object, access will be exclusive thus serialized. there is to be a duplicate somewhere on SO, I just found [this one for MVC](https://stackoverflow.com/q/33602155/1132334) and [this article](http://hogaf.github.io/archive/2014/11/13/why-asp.net-requests-are-processed-sequentially) – Cee McSharpface Apr 24 '18 at 14:09
  • @dlatikay - Looks like that was the problem alright, got around it with `EnableSessionState="ReadOnly"` in the .aspx page - if you want to throw that up as an answer I will accept it... – komodosp Apr 24 '18 at 14:35

1 Answers1

1

Pages sitting on tabs may share a session. If you use the session object, access will be exclusive and serialized:

Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session [..., t]he second request executes only after the first request is finished.

(source)

There is an existing answer on this site describing this and a solution for MVC: ASP.NET MVC 5 concurrent requests are queued even with disabled Session

As you are asking for ASP.NET, the reason is the same but the solution is slightly different. A simple solution is to set the session state to read-only so there will be no concurrent writes:

<% @Page EnableSessionState="ReadOnly" %>

This is a per-page approach. For a per-application approach, place it in your web.config:

<pages enableSessionState="ReadOnly">
    ...
</pages>

Of course this renders the whole session scope useless, no values can be set or changed any more. If you need the session concept, roll your own SessionStateModule or refer to existing implementations like this one on github.

Cee McSharpface
  • 8,493
  • 3
  • 36
  • 77