简体   繁体   English

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

[英]Asp.Net Server-side implementation options for Ajax site

I'm very new to the whole Ajax/Asp.Net stuff so... 我是整个Ajax / Asp.Net的新手,所以...

I know that there are at least a few different ways of implementing the server-side of an Ajax enabled Asp.Net site. 我知道,至少有几种不同的方法来实现启用Ajax的Asp.Net网站的服务器端。

One way is to add static methods to your aspx page's code-behind and mark them with the WebMethod attribute. 一种方法是将静态方法添加到aspx页面的代码隐藏中,并使用WebMethod属性标记它们。

Another way is to use a separate ASMX web service file (which I don't know anything about :) ). 另一种方法是使用单独的ASMX Web服务文件(对此我一无所知:))。

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?) (确保服务器知道Ajax请求来自哪个会话,并确保仅响应登录用户?)

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. 通常,我喜欢使用jQuery向.ashx页面发出请求,该页面负责读取数据并将JSON传递回该页面以进行处理。 It sounds like the other options you suggested are pretty complicated by comparison. 听起来您建议的其他选项相比之下相当复杂。

The two most commonly used options are 两个最常用的选项是

  1. Microsoft ASP.Net AJAX Microsoft ASP.Net AJAX
  2. JQuery partnered with webservices or request handlers (like Jon's answer) JQuery与Web服务或请求处理程序合作(例如Jon的答案)

Microsoft's ASP.Net AJAX is a framework that revolves around two server controls - the ScriptManager and the UpdatePanel. 微软的ASP.Net AJAX是一个围绕两个服务器控件-ScriptManager和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. 您只需使用UpdatePanel包围希望异步的页面部分,所有执行回发的控件(按钮,链接等)将自动变为异步请求,仅更新页面的该部分。 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. 如果您确实计划使用Web服务路由,那么ASMX并非可行之路-目前,它基本上是“传统”技术,您应该考虑使用WCF服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM