views:

142

answers:

1

Hi guys,

i have a case where when the user closes the browser window i have to set an Application Object to null...and for this i will use the JavaScript onbeforeUnload to do the server side work...

so i wanted to know which is better XMLHTTP or an ajax PageMethod...which is faster..??

i have used both and found that pagemethods require less coding...also i dont have to create another aspx page to do the server side work...

can anyone explain the difference between the two and performance wise which would be better???

thanks a lot

A: 

A server-side component should not rely on the user's actions of closing a browser (or logging out of an application). As you know, a client is never trustworthy. For example, the user could use the taskmanager to just kill the browser, or there's a power outage and the user's machine just goes off. Since you cannot rely on whether data from the client is always sent, you need to do this solely on the server-side. For this reasons, there's the notion of session handlers and most framework can hook in additional session handlers.

Those session handlers will either configure a session once it is opened (e.g. a user logs in to the application), or a session is killed (e.g. when a timeout occurs, since the user did not interact with the application for more than X minutes).

And to answer your question: Use XmlHttpRequest, as it's faster.

mhaller

related questions