Let's say that I have a controller with a method "UpdateRecord(int recordID)". This method is supposed to update given record only once (by setting appropiate value to record in database, let's say it's column "IsLock"). To check it I do:
So now I wonder what happens if I do two AJAX request to this method (with the same recordID) one ofter another. Will ASP.NET execute second request only after first request is executed? Or will it execute both simultaneously?
To clarify even more please tell me whether this scenario is possible:
If is is possible, please tell mi how can I secure my method to prevent this scenario from happening?
The gist of it is that a number (probly less than 1000) threads handle a number of request simultaneously, and the rest of the requests get queued. When the queue gets full, the web server starts rejecting requests.
ASP.NET MVC provides three ways (TempData, ViewData and ViewBag) to manage session, apart from that we can use session variable, hidden fields and HTML controls for the same.
There are two methods in Action Result. One is ActionResult() and another one is ExecuteResult().
First of all, it is defined not only by your application but also by IIS settings. I think this article will help.
To answer the ADO.net part - there are several types of data concurrency control, you can read here (Data Concurrency in ADO.NET) about difference and use one that is appropriate in your case.
In your case with locks you are going to change your query from
update T set IsLock = 1 where recordID = 555
to
update T set IsLock = 1 where recordID = 555 and IsLock = 0
and check return value of cmd.ExecuteNonQuery()
to be 1 or 0.
In case it returned 0 record was not updated and lock was set by another user etc.
You might also want to add LockerID
field to your table so your query going to be
update T set IsLock = 1, LockerID = @userID where recordID = @recordID and IsLock = 0
So when opening record you would first execute your lock query and if it was successful you will load record and show edit mode, otherwise show read-only mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With