1

I have a webpage where users can look for clients and select them. After selection they can be send to the webserver through an jQuery Ajax call. On the server database operations and another webservice is called, so this can take a while. That is why I wanted to present a progress bar to the user.

This progressbar is also updated by a Ajax call.

The problem seems to be that asp.net doesn't allow concurrent calls and the session state queues all calls. You can solve this in mvc by setteing the attribute [SessionState(SessionStateBehavior.ReadOnly)]

But I don't find to do this in my page-behind webmethods. Anyway, the worker method is using session state (for security, and updating the session variable for the progressbar). The progress method is only reading and returning the session variable.

Is there a solution for it, or is another approach necessary?

I am using asp.net 4.

1
  • I have found the solution. Will post this this evening. Commented Mar 26, 2012 at 14:32

2 Answers 2

1

You could set the session mode to readonly at the @Page directive in your markup:

<%@ Page Title="Home Page" EnableSessionState="ReadOnly" Language="C#" %>
Sign up to request clarification or add additional context in comments.

3 Comments

But I'm having the other webmethod that uses session state.
@JurgenStillaert, in this case move the readonly PageMethod into another .ASPX for which you can set the EnableSessionState to readonly. This cannot be set per page method. It is per page the same way in ASP.NET MVC it is per controller.
I have tried this. But the call is still queued. When I open the page in a new tab in Firefox, it starts polling. When I initiate the worker webmethod on the other page the polling stops while the worker method is processing. EnableSessionState="ReadOnly" is added in the Page directive of progressbar.aspx, not in the initial page.
0

I have found the solution:

1) The WebMethod only needs to receive the data and start a new thread:

<WebMethod()> _
Public Shared Function importContacts(ByVal contactGuids As String, ByVal campaignGuids As String) As String
  Dim paramsList As New List(Of Object)

  paramsList.Add(contactGuids)
  paramsList.Add(campaignGuids)
  paramsList.Add(HttpContext.Current.Session)

  Dim th As New Threading.Thread(AddressOf processImport)

  th.Start(paramsList)

  Return ""
End Function

The Ajax call is ended quickly and on the browser you can start polling for progress.

2) The thread function needs to convert the parameters first, then you can use the session state:

Public Shared Sub processImport(params As Object)
  Dim paramsList As List(Of Object) = params
  Dim contactGuids As String = paramsList(0)
  Dim campaignGuids As String = paramsList(1)
  Dim _session As HttpSessionState = paramsList(2)

  _session("EmailMarketingDatabase_progress") = 0
  ...
End Sub

3) The progress WebMethod looks like this:

<WebMethod()> _
Public Shared Function getProgressStatus() As Integer
  Return HttpContext.Current.Session("EmailMarketingDatabase_progress")
End Function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.