Ajax 站点的 Asp.Net 服务器端实现选项

发布于 2024-08-02 15:42:14 字数 299 浏览 2 评论 0原文

我对整个 Ajax/Asp.Net 内容非常陌生,所以...

我知道至少有几种不同的方法来实现支持 Ajax 的 Asp.Net 站点的服务器端。

一种方法是将静态方法添加到 aspx 页面的代码隐藏中,并使用 WebMethod 属性标记它们。

另一种方法是使用单独的 ASMX Web 服务文件(我对此一无所知:))。

实现服务器端最常用的选项是什么?每一种都有什么优点和缺点?从安全和会话的角度来看,每一项的表现如何? (确保服务器知道 Ajax 请求来自哪个会话并确保仅响应登录用户?)

I'm very new to the whole Ajax/Asp.Net stuff so...

I know that there are at least a few different ways of implementing the server-side of an Ajax enabled Asp.Net site.

One way is to add static methods to your aspx page's code-behind and mark them with the WebMethod attribute.

Another way is to use a separate ASMX web service file (which I don't know anything about :) ).

What are the most commonly used options for implementing the server-side? What advantages and drawbacks does each one have? And how does each one fare from a security and session perspective? (Making sure the server knows which session the Ajax request is from and ensuring only logged-in users are responded to?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

踏雪无痕 2024-08-09 15:42:14

通常,我喜欢使用 jQuery 向 .ashx 页面发出请求,该页面负责读取数据并将 JSON 传回页面进行处理。相比之下,您建议的其他选项似乎相当复杂。

Typically I like to use jQuery to make the requests to .ashx page that is responsible for reading the data and passing back the JSON to the page to deal with. It sounds like the other options you suggested are pretty complicated by comparison.

清引 2024-08-09 15:42:14

两个最常用的选项是

  1. Microsoft ASP.Net AJAX
  2. JQuery 与 Web 服务或请求处理程序配合使用(如 Jon 的回答)

Microsoft 的 ASP.Net AJAX 是一个围绕两个服务器控件(ScriptManager 和 UpdatePanel)的框架。它比其他选项要重一些,但它确实是一种使网站ajax 化的简单方法。您只需使用 UpdatePanel 包围您希望异步的页面部分,所有执行回发的控件(按钮、链接等)都会自动变为异步请求,仅更新页面的该部分。没有编码或任何东西。

如果您确实计划使用 Web 服务路线,那么 ASMX 不是最佳选择 - 目前它基本上是一种“遗留”技术,您应该考虑使用 WCF 服务。

The two most commonly used options are

  1. Microsoft ASP.Net AJAX
  2. JQuery partnered with webservices or request handlers (like Jon's answer)

Microsoft's ASP.Net AJAX is a framework that revolves around two server controls - the ScriptManager and the UpdatePanel. It's a bit more heavyweight than other options, but it's certainly a simple way of ajaxifying your site. You simply use an UpdatePanel to surround the portion of the page that you wish to be asynchronous, and all your controls that do postbacks (buttons, links, etc.) automatically become asynchronous requests that will only update that portion of the page. No coding or anything.

If you do plan on using the webservice route, ASMX is not the way to go - it's basically a "legacy" technology at this point and you should consider using WCF services instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文