扼要翻译《Programming Microsoft ASP.NET》关于什么是ASP.NET的一节

What's ASP.NET, Anyway?

Prior to the advent of ASP.NET, three main technologies and platforms were available to develop Web applications: ASP, Java Server Pages (JSP), and the open source Web platform commonly referred to as LAMP (Linux plus Apache plus MySQL plus either Perl, Python, or PHP as the programming language).


For completeness, we should also mention a couple of platform-specific, lower-level technologies that ASP and JSP rely on. ASP is actually an Internet Server Application Programming Interface (ISAPI) extension, whereas JSP is implemented as a special servlet application. ISAPI extensions on IIS-based platforms and servlets on Java-based systems let you create server-side, Web-deployed applications using a more classic approach. You write a module that builds and renders the page rather than declaratively design the page using a mix of markup text and embedded code.

Although each has language-specific and architecture-specific features, all these Web development platforms are designed to create interactive pages as part of a Web-based application. To some extent, all enable developers to separate programming logic from the page layout through the use of components that the page itself is responsible to call and render. Aside from this common ultimate终极 goal, significant differences exist among those platforms, most of which relate to the programming model and languages they promote and support. For example, JSP exploits利用 the Java framework of classes and, with JavaBeans, provides an effective extensibility model for reusing components. In addition, JSP supports tag customization and lets developers associate code with a custom tag definition. Finally, because it's a key element of the Java 2 Enterprise Edition (J2EE) platform, JSP relies on the Java language, a first-class language as opposed to the scripting languages used by both ASP and LAMP platforms. So how does ASP.NET fit in exactly?

Like ASP and other Web development environments, ASP.NET also works on top of the HTTP protocol and takes advantage of HTTP commands and policies to set up two-way, browser-to-server communication and cooperation. What really differentiates ASP.NET from the plethora of other Web development technologies—and what makes it especially revolutionary—is the abstract programming model it propounds提出, the Web Forms model. In addition, the whole ASP.NET platform comes as a native part of the Microsoft .NET Framework. To be sure you grasp揪住 the importance of this last point, let me explain. ASP.NET applications are now compiled pieces of code, are made of reusable and extensible components, can be authored with first-class languages (including C#, Microsoft Visual Basic .NET, JScript .NET, and J#), and can access the entire hierarchy of classes in the .NET Framework.
和过去的技术一样,ASP.NET也是工作在HTTP协议上的,也要处理HTTP命令,也要处理浏览器-服务器交互操作,那么ASP.NET的革命性在哪里呢?革命在一种新抽象编程模型—Web Forms模型!此外,ASP.NET是Microsoft .NET Framework平台重要组成部分,这点很重要。得益于.NET Framework,ASP.NET应用现在是编译型应用,由可重用和扩展的组件组成,也使用编译语言处理逻辑了。此外还可以访问.NET Framework整个强大的类库。

In short, ASP.NET combines the best of all worlds. It is syntax compatible (and to a large extent, also language compatible) with ASP. It provides the same object-oriented features as JSP applications (tag customization, first-class compiled languages, components, extensibility, and reusability). And as icing on the cake, ASP.NET delivers a wealth of goodies, tools, and powerful system features that can be effectively grouped within the blanket expression tools for abstracting the HTTP programming model. Lots of programmer-friendly classes let you develop pages using typical desktop methods. The Web Forms model promotes an overall event-driven approach, but it's deployed over the Web and has the potential to target any vendor's platform through the support of XML.


From a technical point of view, ASP.NET adopts the best of the ASP and JSP programming models. Conversely, it doesn't inherit much from the LAMP platform in terms of technical aspects. The appeal of LAMP is that it excels as a robust and extensible (because it is open-source) platform with flourishing and proactive grassroots community sites and Web boards.
LAMP 平台的确有一些特别,保留……

Programming in the Age of Web Forms

A key point I need to explain so that you understand the rationale behind the ASP.NET Web Forms model is that there is a need to provide a better strategy to deal with the strong and growing demand for cheap Web interaction. As a matter of fact, the HTTP protocol, especially its stateless nature, creates a sort of bottleneck for the development of Web applications. On the other hand, the inherent固有的 simplicity of HTTP is the key to its worldwide adoption and effectiveness—in short, we probably couldn't have the Internet as we know it without a protocol like HTTP. Yet, as demand increases, programmers have to devise发明设计 better ways of setting up easy and effective communication from the client to the server and vice versa.
我来解释一下一个关键点,随着现在对“廉价的WEB交互”日益需求,ASP.NET 提供一种更好的策略—Web Forms模型。实际上,正是因为工作在HTTP协议上,尤其是它的无状态的性质,已经成开发WEB应用的一大瓶颈了。话说回来,就是因为HTTP固有的简单性,才是它在全球内普及的关键,简单的说,如果没有像HTTP这样的协议,也就没有今天的互联网了。所以,有求必应,程序员必须发明设计出更好方法促使客户端-服务器交互更容易更有效。

Various techniques have been experimented with over time to smooth the communication across different pages and across multiple invocations招唤请求 of the same page. Programmers are used to thinking in terms of a client-generated action that results in a server-side reaction. Such a basic and fundamental pattern simply cannot be accomplished, at least not literally, over the Web. A certain degree of abstraction and some system-provided services are needed to make smooth communication happen. Although they aren't perfect, JSP and ASP let programmers target any browser while coding against a relatively familiar and understandable model. ASP, much more than JSP, thinks declaratively and has quite a slim稀少 and scanty缺乏的 object model. Overall, programmers who become Web programmers are forced to adopt a different mindset and toss the familiar action/reaction paradigm out the door.

Event-Driven Programming over HTTP

With Web Forms, the event-driven model of interaction finally comes to the Web. Implementing an event model over the Web requires any data related to the client-side user's activity to be forwarded to the server for corresponding and stateful processing. For the model to work, the server needs to process the output of client actions and trigger reactions while being aware of the overall state of the application. The state of the application contains two types of information: the state of the client and the state of the session. The state of the client is easily accessible through the syntax and the implementation of the <form> HTML element. But what about the overall state of the session?

As mentioned, HTTP is a stateless protocol, which means two successive requests across the same session are resolved by newly instantiated environments in which no session-specific information is maintained, except all the information the application itself might have stored in global objects. In ASP, reentrant forms are a common way to work around such a system limitation. A reentrant form is an HTML <form> element that posts to the same page that contains it. Reentrant forms alone do not fully solve the issue. However, by combining them with code blocks and hidden fields storing state information that is critical for the page, many developers elegantly overcame克服 the obstacle障碍.

What was once an ASP best-practice has been standardized and integrated in the ASP.NET runtime to become the key feature that endows ASP.NET applications with automatic state maintenance. The ASP.NET runtime carries the page state back and forth across page requests. When generating HTML code for a given page, ASP.NET encodes and stuffs the state of server-side objects into a few hidden, and transparently created, fields. When the page is requested, the same ASP.NET runtime engine checks for embedded state information—the hidden fields—and utilizes any decoded information to set up newly created instances of server-side objects. The net effect of such a mechanism is not unlike the Windows Forms model on the desktop and is summarized in Figure 1-1.

The Windows Forms model stems from the typical event-driven desktop programming style. No matter what connectivity exists between the client and server components, the server always works in reaction to the client's input. The server is aware of the overall application state and operates in a two-tier, connected manner. The Web Forms model needs some machinery to support the same event-driven programming model. In Figure 1-1, the needed machinery is represented by the state deserialization that occurs when the page is requested and the state serialization performed when the HTML response is being generated.
WEB表单模型需要一些机制来支持“事件驱动编程模型”,表现在页面在往和返两个方面,deserialization previous state处理请求页面前反串行化之前的状态信息,serialization current state 处理请求页面后返回前串行化当前状态

The ASP.NET object model is a branch of the .NET Framework and is designed to provide a server-side counterpart to virtually any HTML page elements, such as HTML tags like <form> and <input> and page-wide tags like <link> and <script>. In addition, the ASP.NET object model includes numerous components (called server controls or Web controls) that represent more complex elements of the user interface (UI). Some of these controls have no direct mapping with individual HTML elements but are implemented by combining multiple HTML tags. Typical examples of complex UI elements are the Calendar control and the DataGrid control. An ASP.NET page is made of any number of server controls mixed with verbatim字面 text, markup, and images. Sensitive data excerpted from the state of each constituent构成的 control is silently stored in hidden fields, and it forms the context of that page request. The association between an instance of the page and its state is unambiguous, not programmatically modifiable, and controlled by the ASP.NET HTTP runtime. We'll delve more deeply into this topic in Chapter 2, which also covers the Web Forms architecture in detail.

Building a Server-Side Abstraction Layer

Every conversation between browsers and Web servers consists of the exchange of packets similar to the ones we have just examined. If the requested URL is an HTML page, the Web server typically reads the contents of the .html file and flushes it into the body of the response packet. If the URL is an ASP.NET page, a special IIS module gets involved. The module is an IIS plug-in known as an ISAPI extension. An ISAPI extension is a dynamic-link library (DLL) registered on a per-file extension basis. An ISAPI extension registered to handle .aspx files will get involved whenever a request comes in for this type of resource.

The ISAPI extension analyzes the request and uses any contained information to configure the server-side environment that will actually process the source of the page.
这个配置服务器环境,根据提交过来的信息,怎么配置,或者简单配置什么东东,有,会话,ASP里,那么提交过来的HTTP头里会有甜饼,里面有会话ID 的。

While processing the page request, the ISAPI extension parses the body of the request and exposes any information found through a more programmer-friendly object model. For example, instead of remaining a simple name/value string, the EmpCode variable is moved within an application-wide collection—the Request.Form collection. This represents a first level of abstraction built over the raw HTTP programming model. Objects such as Request, Response, and Server form the HTTP context for the call and, as such, represent the minimum set of objects you find in all Web development platforms, including JSP, ASP and, of course, ASP.NET. In ASP.NET, though, you find much more
你玩过的东东,Request, Response, and Server 被再正名为“在没加工过的HTTP编程模型”的第一层抽象。

个人分类: 应用开发
想对作者说点什么? 我来说一句