views:

84

answers:

3

Hi!

I have a .NET application that access methods located on handlers through AJAX calls. This AJAX calls are fired, generally, when the user clicks on certain buttons. My problem happens when the user clicks the buttons more than once. It messes up with all my object´s state.

How do u take care of it? I know I can block the user click until the first call finishes, but I would like to find a solution to take care of this matter in the server side. Any idea?

Thanks!

+1  A: 

in the onclick method, remove the button's onclick handler, then run the ajax call in the background with setTimer, and return true...

when the ajax completes, you can optionally re-attach the onclick handler.

jspcal
Yes, this a way of doing it. But I would like to create something to take care of it in the server side.
tucaz
on the server you can set a flag in the session and check that before running...
jspcal
What if I don´t have a session server? I also have load-balance so I would need to "save" this info in a place that would work for a web farm.
tucaz
if no sessions, you can embed a random code in the ajax script, then check if that code has been seen before running...
jspcal
+1  A: 

I believe that this is best achieved using client code. If you are using jQuery then one() may be an elegant solution. Alternatively you could set a variable to true when starting a request and set it to false when finished. Then prevent all further requests while the variable is set to true.

Doing it server side won't work. The server may have finished processing, but the message hasn't arrived to the client yet. The client then makes a new request. The server reacts to it as it is a new one. Havoc may occur in cases like this.

kgiannakakis
Maybe... I know that this is very achievable in client code, but I also want to be able to ignore duplicated requests as a defense mechanism because someone could access the site, read the javascript and work on some kind of DOS attack. I know that this is a long shot, but I´m looking for something in the server side too just to be sure. Thanks, though!
tucaz
For server side there's no other way than using a session variable or a database. In my opinion both are cumbersome and expensive solutions. With the database for example, every request will be burden with at least 3 database queries (checking the state, persisting the start of the operation, clearing it all at the end), which have nothing to do with the main processing.
kgiannakakis
Yeah. Maybe I could use Application object and ignore the fact that it´s not the same object for all web farm servers. At least I would avoid problems in the same server.
tucaz
A: 

Hi Use jquery blockUI plugin. when user click on button first time then lock user page. after completing user task unblock the page.

Refer http://malsup.com/jquery/block/#

Yashwant Chavan
Great Plugin! However, I'm still looking for a solution to block the server side.
tucaz