asp.net mvc 2 multithread
صفحه اصلي

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 webserver. 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


Selling upper management on converting to ASP.NET from Classic ASP

1:

Membership provider stopped working on using Membership Provider in ASP.Net MVC
This is a limitation with the browser only sending one POST request at a time and queuing the another requests. Design decisionsIts not a limitation with the web server.. ASP.NET Exception Handling in background threads One way to simulate multiple requests is to use a tool such as tinyreceive which is part of the IIS 6.0 toolkit. MVC2 or WCF for an XML/JSON REST API?For your test you will need to use the multiple threads option.. How do you update the aspnetdb membership IsApproved value? Hope this helps.. Restrict file types allowed for upload asp.net
MVC & EF - using

86 out of 100 based on 71 user ratings 746 reviews

^