Download this article: [URL = http: //download.microsoft.com/download/4/b/4/4B44505A-ECDA-4DD3-8A0E-71D8C7A8B9BB/ASPCOLUMN0311.EXE] AspColumn0311.exe [/ url] (534KB)
*
This page
What is ASP.NET? What is ASP.NET?
What is the difference between ATL Server? What is the difference between ATL Server?
ATL Server and ASP .NET ATL Server with ASP .NET
ASPX file with srf aspx files with SRF
"Solid" object "inherent" object
Manage UI Elements Management UI Elements
Session status session status
Small knot
The task of the web server is to accept the incoming HTTP request and return some information useful to the caller (regardless of the caller is a man, or the machine when the web service). Windows contains the mature structure of processing requests - IIS and its related extensions. However, design IIS starting from scratch is very monotonous, and it is easy to make mistakes. A better way to manage HTTP requests is to manage it with a framework located at the top of IIS. This month I will compare two main technologies for creating a Windows web application: ASP.NET and ATL Server. Each framework has some specific advantages and disadvantages. In this section, I will focus on how to use ASP.NET to manage web-based UIs. Next time I will focus on how to use these two frameworks to build web services and other functions.
What is ASP.NET?
ASP.NET is a class library designed for HTTP requests. In addition to the class library, ASP.NET also contains several IIS components of management requests. These components include an ISAPI DLL named ASPNET_ISAPI.DLL and a auxiliary process called ASPNET_WP.exe. ASP.NET also installs new mappings in IIS, redirects ASPX, ASCX, ASHX, and ASMX file requests to ASPNET_ISAPI.DLL. At this point, ASPNET_ISAPI.DLL will request the request to ASPNET_WP.exe, in which the ASP.NET loads the required class to serve the request.
The ASP.NET has a very convenient object model with a managed class named httpcontext. If you have written a standard ISAPI DLL, you must know about HTTPEXTensionProc that is included in the extension_control_block and passed to the ISAPI DLL. When the management request, the ISAPI DLL checks the structure to obtain information such as an environment ID, query string, and a function of reading and writing clients. ASP.NET will be packaged in the HTTPContext class. ASP.NET also includes a fundamental structure that manages web-based UI (via system.web.ui.page) and management web services (via System.Web.Services.WebService class, and [WebMethod] properties).
ASP.NET is object-oriented. Each request passed through the ASP.NET application is handled by a class named IHTTPHANDLER, which can implement the interface. This creates an architectural architecture. You can choose to use the ASP.NET page architecture or web service architecture, or you can write processing logic from the head. Figure 1 shows the path to the ASP.NET request taken.
Miissues0311ASPColumnfig01
Figure 1 Lifecycle for request on ASP.NET
The ASP.NET UI-Processing Architecture is centered on the web.ui.page class (represented by the ASPX file). The ASPX file can include neat HTML code and server-side controls. When ASP.NET encounters a server-side control (by "runat = server" attribute), it instantiates a class (for example, Button and ListBox controls). Essentially, the ASP.NET page is processed as a tree of these server-side controls (text and tags on this page are packaged as LiteralControl class) - Other are server-side controls. When the page is required to render itself, this page is only traversed to the control tree, and the "tell" each node on the tree presents them itself. ATL Server works a bit different. Back to top Back to top
What is the difference between ATL Server?
ATL Server is a C template library for creating ISAPI DLLs. When creating IIS for the first time, developers must write ISAPI extensions from head or from the MFC's ISAPI DLL class as the starting point. Generating an ISAPI DLL using the original C or MFC code that requires manual writing extension code. For example, MFC ISAPI does not provide developers with a form-based architecture. Any HTML tag ended over the client must be sent by manual.
ATL Server combines a form-based method with runtime speed and the flexibility of C . The Web site built using the ATL Server consists of three basic components: server response file (SRF), application DLL, and essential ISAPI extensions. SRF is a new file that ATL Server installed in IIS. The SRF mapping points IIS to the ISAPI DLL of the application, which in turn will process the processing to one or more application DLLs. SRF includes a special new tag syntax, which is essentially invoking entry points in the application DLL. Figure 2 shows the path employed by the ATL Server-based request.
Miissues0311ASPColumnfig02
Figure 2 Path based on the request of ATL Server
The ATL Server application consists of many DLL (ISAPI extensions and application extensions) and HTML generating templates called SRF (previously mentioned). This architecture is clearly separated by the application representation and application logic. The representation of the webpage is defined by the SRF containing HTML and special tags. These tags call the ATL Server application DLL.
Since most web applications target the target platform of WINDOWS, the ATL Server application is built on the ISAPI DLL. The ATL Server project contains a single ISAPI extension DLL that can handle rough requests. The ATL Server application also includes one or more application DLLs for a variety of precise request processing. The process of processing the request is derived from CREQUESTHANDLERT and also contains the code that you have unique to handle the SRF.
These handler classes include dictionary that associates the request handler class and request handler DLL and associates an alternative method with the SRF tag. In addition to alternatives, CREQUESTHANDLERT also includes methods and members variables for accessing standard web application elements, such as form variables, cookies, request streams, and response streams.
When the browser finds the .SRF URL via HTTP, IIS knows the site with the ATL Server application's ISAPI DLL. The ATL Server application then turns on the SRF and loads the DLL of the application (if they have not been loaded). The application then transmits the request to the default request processing program class, which analyzes SRF to find a mark with a special mark. Each time a tag occurs in the SRF, the application calls an alternative to a handler class existing in an application DLL. This alternative dynamically generates the output of the browser. Figure 2 shows the path to the request of the ATL Server application. Back to top Back to top
ATL Server and ASP .NET
Although ATL Server and ASP.NET are based on the ISAPI architecture, they have different requests. To illustrate these different points, let's take an application example, the application collects the development of the personal name and his (or her). I will explain how to develop user interfaces and how to use session status. In the next part of this column, I will examine some other features (such as cache and browser capabilities), and the working principle of Web services on each frame. Figure 3 compares some of the two frames.
Back to top Back to top
ASPX file with SRF
ASP.NET and ATL Server introduced a new file extension for the ISAPI architecture. The file types introduced by ASP.NET include ASPX, ASMX, ASCX, and ASHX, and some other types. In the ASP.NET framework, each of these file types has a corresponding managed class. For ASPX files, such classes are system.web.ui.page. This Page class is responsible for presenting a UI-based web page. Figure 4 shows a simple ASPX file.
The main matters you should pay attention to the ASPX file is the "Runat = Server" property of the inheritance instructions near the top of the web page, tag, and drop-down list tag. These tags indicate the class of the class in the code hidden file in the Visual Studio in Visual Studio.
In contrast, SRF contains the most standard, most common HTML tag. ATL Server has no server-side component architecture. However, it does introduce the concept of server response tags. These special tags are represented by double braces ({{}}). When the ATL Server request architecture encounters a server response tag, it expects to find a corresponding handler function in the application DLL öð. Figure 5 shows a simple SRF, which is displayed substantially the same as the user interface in the ASPX example of Figure 4.
The most important thing to note in this document is a special tag enclosed by double large brackets. For example, near the top of the SRF, you will see the handler tag ({{Handler ...}}) that specifies the application default handler. This tells the ATL Server application which DLL is loaded to find a function called by the response tag. Other response markers indicate the entry point in the application DLL.
Back to top Back to top
"Inherent" object
Both ASP.NET and ATL Server include similar inherent requests and responses, this and typical asp ò »ñù¡ £ In ASP.NET, they are represented by HttpRequest and HttpResponse classes. In ATL Server, they are represented by ChttpRequest and ChttpResponse classes. In each frame, their use is basically the same. The request object encapsulates such as request parameters and requests URL. The response object contains the function of outputting the text to the client. For example, in order to insert "Hello World" to a "Hello World", you only need to call Response.Write, as follows: protected void helloworld ()
{
Response.write ("Hello World");
}
In order to output "Hello World" to the client-based client-based client, use the ChttpResponse object, as shown below:
[tag_name (Name = "Hello")]]
Http_code onhello (void) {
M_HTTPRESPONSE << "Hello World!";
Return http_success;
}
Note how to call the onhello function using the server response tag in Figure 5. (This tag is as follows: Hello.)
Back to top Back to top
Manage UI elements
Each framework has different methods to manage UI elements. As mentioned earlier, UI support in ASP.NET supports the server-side control model. Represents code (ASPX file) declares the server-side elements on the web page with the "Runat = Server" property. As long as the corresponding classes are declared in the code hidden class, it is easy to programmatically access the control. For example, the code in Figure 4 illustrates several server-side control elements (eg, submitting buttons, text box elements, and drop-down lists). The code hidden page will declare the Button, TextBox, and DropdownList classes as members of the page so that they can be programmed to use these UI elements. In order to find data in the TextBoxName element, you only need to access the text attribute, as shown below:
String s = this.TextBoxName.Text;
The ASP.NET server-side control also has the advantage of automatically tracking view status. When the browser comes from accessing the server, the UI element (such as the drop-down list box and the radio button) maintains their consistent state. For example, the item selected in the drop-down list box is the item displayed. No need to write any special code to ensure that the behavior of the control is correct.
ATL Server has no such control model. You can only manage the UI through the server response tag. In order to fill the drop-down list, the ATL Server example populates it with a server response function (see {{showfeatureselection} tag in Figure 5. Figure 6 illustrates how the server response function is inserted into the drop-down list.
The ATL Server is different from the ASP.NET, which does not track the status of the view. In order to maintain the consistency of the drop-down list, the code displayed in Figure 6 is required. These code check the parameters incorporated by the string and find which one selected. Rendering code ensures that the user selection item contains the "selected" attribute in the option tag.
Back to top Back to top
Session status
The management session state is very convenient in ASP.NET. The ASP.NET assist process handles low-level details. When a new client starts a session, ASP.NET will automatically assign a new session object - a dictionary that contains the name-value. The System.Web.ui.page class contains a reference to the current customer session information. Accessing the status of the customer can only use the indexer to access the session dictionary. Figure 7 shows the code that creates a new session variable and the code that uses ASP.NET to access them. In ATL Server, the management session state is slightly complicated. Although ISAPI DLL is generated by using the ATL Server wizard, you still need to write code to create and access session objects. The code in Figure 8 illustrates how to create and access session variables in the ATL Server.
The ValidateAndexchange function is entered by the ATL Server wizard. This method is called at the beginning of each request, just like the INIT included in the ASP.NET Page class. ValidateAndexchange Gets an interface (via queryservice) for the ISAPI DLL's Session Manager. If there is no session cookie in the title, this method creates a new session and add a session cookie to the response. If this is the continuation of the existing session, these codes use session information to populate names and age variables. Note that the session variable is represented by a COM variable.
Back to top Back to top
summary
This month, I quickly navused ASP.NET and ATL Server. These frameworks represent the most advanced ways that currently process the HTTP request on the Windows platform. Each framework is constructed above the tested ISAPI architecture, which has occurred almost ten years ago. ASP.NET and ATL Server map their file extensions to a specific DLL. ASP.NET DLL is ASPNET_ISAPI.DLL. The ATL Server DLL is generated by ATL Server, but for most of it, it is a code that can be used repeatedly. In this regard, an advantage of ATL Server is that it can actually consult (and change) the original ISAPI request processing code for special applications.
Although any of the frameworks can be used to prepare a substantially equivalent application, it is necessary to compete for standard issues. Typically, it is very direct to develop ASP.NET applications with a hosted language and an ASP.NET framework. However, you will be dominated by the framework (although ASP.NET uses its scalability that has alleviated flexibility). On the other hand, as long as the ATL Server application has passed IIS, it contains most DLL μ ÷ óã - a high-performance suggestion. The ATL Server application is written with C , so you have many control and necessary responsibilities.
Next time I will compare other features of ASP.NET and ATL Server, including buffering status, security, and web services.
Figure 3 to Figure 8 Link:
Http://www.msdn.microsoft.com/msdnmag/issues/03/11/ASPCOLUMN /DEFAULT.ASPX?fig=true#fig3
George Shepherd is specially engaged in the development of the .NET Framework software. He is the author of Programming With Microsoft Visual C . Net (Microsoft Press, 2002), and is also an Applied .NET (AdDison-Wesley, 2001). He taught exvelorners at the seminar, he was a contributor to Syncfusion .Net tools.