Ajax PageMethods 与 XMLHTTP
我有一种情况,当用户关闭浏览器窗口时,我必须将应用程序对象设置为 null...为此,我将使用 JavaScript onbeforeUnload 来执行服务器端工作...
所以我想知道哪个更好XMLHTTP 或 ajax PageMethod...哪个更快..?
我使用了这两种方法,发现 pagemethods 需要更少的编码...而且我不必创建另一个 aspx 页面来完成服务器端工作...
任何人都可以解释两者之间的区别以及性能方面哪个会更好???
多谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
服务器端组件不应依赖于用户关闭浏览器(或注销应用程序)的操作。如您所知,客户永远不值得信任。例如,用户可以使用任务管理器来终止浏览器,或者停电并且用户的计算机突然关闭。由于您不能依赖是否始终发送来自客户端的数据,因此您需要仅在服务器端执行此操作。由于这个原因,就有了会话处理程序的概念,大多数框架都可以挂接额外的会话处理程序。
这些会话处理程序将在会话打开后对其进行配置(例如,用户登录到应用程序),或者会话被终止(例如,当发生超时时,因为用户没有与应用程序交互超过 X 分钟) 。
并回答您的问题:使用 XmlHttpRequest,因为它更快。
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.