Reputation: 2358
Is it plausable to use a lock for a POST within MVC? Is there situation like using a webfarm that would invalidate the lock? I usually use database locks but my particular situation is pretty difficult to manage and its simpler to use a Monitor. I dont want to get into discussing why I need a lock just want to know if there are situations when it wont work as desired.
private static object Lockable = new Object();
public ActionResult Submit()
{
lock(Lockable)
{
}
}
Upvotes: 0
Views: 1696
Reputation: 47660
In order to achieve a lock over a webfarm you need to have a shared resource on the network (such as a cache server), and you need to use that to achieve webfarm-safe locking. I think that's the simplest solution.
You can also isolate the component you want to serialize calls to and access to it over network.
There is another option of creating a MSDTC compliant component that can enlist into distributed transactions so all callers are enforced to serialize their calls. However that requires setting up all environment to work with MSDTC, Enterprise Services etc.
Upvotes: 3
Reputation: 2123
As you said yourself, in the case of few web servers / different processes, your lock will only work for the current process, which means it wont affect other running instances of ur application, if such exist.
Upvotes: 1