开发者

asp.net mvc 2 multithread

I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm expecting). I have a controller httppost action that processes credit cards. I'm setting a session variable on the server to let me know if a user has attempted to process a card. I clear that session variable when I'm done. I am doing some very quick posts to test the process and the session variable is coming back null everytime because I clear the session variable at the end of the process. I have some debug prints that show me that the all requests are processed synchronously. That is...the first attempt occurs, it fails, session variable is cleared, second attempt tries and fails and the variable is cleared, etc... My first thought was that this was a side effect of debugging and that it just lined requests up for debugging purposes using the local w开发者_开发百科ebserver. So I put it on a development server and the same thing is occurring. Multiple submits/posts are processed synchronously. I even put a System.Threading.Sleep in there to make sure it would stop right after I set the session variable and it still won't even START the second request until the first is done.

Has anyone else seen this behavior? My understanding was that a worker process was spawned for each request and that these actions could happen asychronously.

Here's some psuedo code

if (Session["CardCharged"] != null)
    return RedirectToAction("Index", "Problem");
Session["CardCharged"] = false; //starting the process
System.Threading.Thread.Sleep(10000);
//charge card here

if (!providerResponse.IsApproved)
{
    System.Diagnostics.Debug.WriteLine("failed");
    Session["CardCharged"] = null; //have to allow them to charge again since this failed
    return View(myModel);
}

Session["CardCharged"] = true;
return RedirectToAction("Index", "OrderComplete");

I should mention that my code ALWAYS fails the credit card check for testing purposes. I'm trying to test the situation where processing is STILL occurring and redirect the user elsewhere. I have set a dummy session variable elsewhere to assure that the session id "sticks". So I know the session id is the same for each request.

Thanks


This is a limitation with the browser only sending one POST request at a time and queuing the other requests. Its not a limitation with the web server.

One way to simulate multiple requests is to use a tool such as tinyget which is part of the IIS 6.0 toolkit. For your test you will need to use the multiple threads option.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜