ASP.Net: IHttpAsyncHandler and IRequiresSessionState not working
I have implemented an IHttpAsyncHandler. I am making about 5 different AJAX calls from a webpage that has widgets to that handler.
One of those widgets takes about 15 seconds to load(because of a large database query) the others should all load in under a second. The handler is responding in a synchronous manner.
I am getting very inconsistent results. The ProcessRequest method is using Session and other class level variables. Could that be causing different requests to use the same thread instead each there own?
I'm getting this...
Request1 ---> response 1 sec
Request2 ---> response 14 sec Request3 ---> response 14.5 sec Request4 ---> response 15 sec Request5 ---> response 15.5 secbut I'm looking for something more like this...
Request1 ---> response 1 sec
Request2 ---> response 14 sec Request3 ---> response 1.5 sec Request4 ---> response 2 sec Request5 ---> response 1.5 secWithout posting too much code my implementation of the IHttpAsyncHandler methods are pretty standard.
private AsyncProcessorDelegate _Delegate;
protected delegate void AsyncProcessorDelegate(HttpContext context);
IAsyncResult IHttpAsyncHandler.BeginProcessRequest(HttpContext context,
AsyncCallback cb, object extraData)
{
_Delegate = new AsyncProcessorDelegate(ProcessRequest);
return _Delegate.BeginInvoke(context, cb, extraData);
}
void IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
{
_Delegate.EndInvoke(result);
}
Putting a debug break point in my IHttpAsyncHandler.BeginProcessRequest method I can see that the method isn't being fired until the last Process is complete.
Also my machine.config has this entry... processModel autoConfig="true" with no other properties set.
I'm calling the han开发者_JS百科dler like this...
$.ajax( { type: "GET", url: "../HTML/HtmlHandler.ashx", cache: true, dataType: "text", data: { html: name }, success: function(html) { //$(function() { //console.log(tabname); //console.log("msg:" + msg); $("#" + name + "holder").html(html); //checkAllLoaded(); ClientHome_init(''); //}); }, error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#" + name + "holder").html("<span>Error retrieving widget.</span>");
//console.log("error:" + tabname);
//checkAllLoaded();
}
}
What else do I need to check for?
Just incase someone else has this problem changing IRequiresSessionState to IReadOnlySessionState fixed the problem for me.
Your problem here is probably not with your server code. The nature of javascript is that it is synchronous. Even when you are using asynchronous AJAX requests, I find that javascript will rarely allow you to make two HTTP requests at the same time.
精彩评论