0

I understand that ASP.NET serves requests using worker threads. Therefore client A and client B can make requests and the requests are dealt with concurrently.

Can a client make multiple requests concurrently. Please see the code below:

Imports System.Threading
Partial Class Default5
    Inherits System.Web.UI.Page

    Dim intCount1 As Integer, intCount2 As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'If Session("Test") = "" Then
        Session("Test") = Request.QueryString("ID")
        'End If
        Response.Write(Session("Test"))
    End Sub
End Class

Imports System.Threading
Partial Class Default4
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("Test") <> "" Then
            For intCount1 = 0 To 10
                Response.Write(Session("Test") & "," & intCount1 & "<br>")
                Thread.Sleep(1000)
            Next
        End If
    End Sub
End Class

Please open Default5.aspx by specifiying this URL: default5.aspx?id=1 and open another page with this URL: default5.aspx?id=2. Then from the browser with default5.aspx?id=1 open navigate to default4.axpx (by specifying the URL) and whilst this is running, navigate to default4.axpx from the browser with default5.aspx?id=2 open. The result in both cases is:

2,0
2,1
2,2
2,3
2,4
2,5
2,6
2,7
2,8
2,9
2,10

The session variable is 2 in both cases (I understand why this is). Please see a question I asked yesterday: ASP.NET - Accessing web page twice from client. The session variable is not 2 in both cases in this example.

My question is; can ASP.NET process multiple requests from the same client at the same time. Wins response seems to suggest that one request is processed at a time.

Community
  • 1
  • 1
w0051977
  • 15,099
  • 32
  • 152
  • 329

2 Answers2

1

For anyone else finding this post, if you don't need write access to Session, declaring readonly access allows ASP.NET to run requests concurrently because it doesn't have to obtain a session lock:

In pages:

EnableSessionState="ReadOnly"

Or in generic handlers by implementing:

IReadOnlySessionState
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76
0
My question is; can ASP.NET process multiple requests 
from the same client at the same time.

Yes if you disable session, or use a handler with out session, or made a totally custom session of yours.

Its may also help if you use more than one pool for the same web applications making a "web garder"

You can also read:
ASP.NET Server does not process pages asynchronously
Trying to make Web Method Asynchronous
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • What do you mean by: "if you disable session"? The example code I have provided in the question uses session variables. Thanks. – w0051977 Oct 20 '12 at 12:28
  • @w0051977 Yes I see the example that use session variables as a test, if you need them and you can not avoid them you can not with the existing session code from asp.net - so you need to make your custom session handle code (I have made one for that reason, is not so difficult) – Aristos Oct 20 '12 at 12:31
  • @w0051977 The session is actually connect the cookie of the user with a line on a database that keep some data there. – Aristos Oct 20 '12 at 12:32
  • What happens if you have web server A and web server B. The user can choose which web server to go to when using the application? – w0051977 Oct 20 '12 at 12:33
  • @w0051977 Its all about programming. If you programming it, user can do that. If you let the automatic existing procedure that select what server or what pool is going to be used, then you can not do that. – Aristos Oct 20 '12 at 12:36
  • @Artistos, one more thing before I answer. Can you confirm that if a user can chooses server A to access the application on the first request and server B for the second request then the session variables could be shared between the requests (from the same client)? – w0051977 Oct 20 '12 at 12:38
  • @w0051977 You need to setup the session to shared among server. This can be done only using SQL server. Or else they will have different session variables - To avoid that usually they use the sticky technique that is mean the user that starts with A, stay on A – Aristos Oct 20 '12 at 12:40
  • I have not setup any session handlers etc. What is the default behaviour e.g. if client A accesses page A via server A and concurrently accesses page A via server B (with different session variables). Is there no possibility that these session variables will be shared? – w0051977 Oct 20 '12 at 12:44