ATL server and ASP. NET

Source: Internet
Author: User
Tags what is asp
Download the code in this article: [url = bytes (534kb)
*
Content on 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 and ASP. NET
Aspx file and SRF
"Inherent" object
Manage UI elements manage UI elements
Session status session Status
Summary

The task of the Web server is to accept incoming HTTP requests and return some useful information for the caller (whether the caller is a person or a machine in the Web Service ). Windows contains a mature structure for processing requests-IIS and its related extensions. However, designing IIS from the beginning is tedious and error-prone. A better way to manage HTTP requests is to use a framework located at the top of IIS to manage them. This month I will compare two main technologies used to create Windows Web applications: 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 to process HTTP requests. In addition to class libraries, ASP. NET also contains several IIS components that manage requests. These components include the isapi dll named aspnet_isapi.dll and the auxiliary process named aspnet_wp.exe. ASP. NET also installs a new ing in IIS to redirect file requests from aspx, ascx, ashx, and asmx to aspnet_isapi.dll. So far, aspnet_isapi.dll directs the request to aspnet_wp.exe. In this process, ASP. NET loads the required classes to provide services for the request.

Centered on the managed classes named httpcontext, ASP. NET has a convenient object model. If you have written a standard isapi dll, you must understand the httpextensionproc information contained in extension_control_block and passed to isapi dll. When managing requests, isapi dll checks the structure to obtain information such as the Environment ID, query string, and read/write client functions. ASP. NET encapsulates all the information in the httpcontext class. ASP. net also includes the management of web-based UI (through the system. web. UI. page class) and manage Web Services (through the system. web. services. the basic class structure of the WebService class and [webmethod] attribute.

ASP. NET is object-oriented. Each request passed through an ASP. NET application is processed by the ihttphandler class, which can implement interfaces. This creates a highly scalable architecture. You can choose to use the ASP. NET page architecture or Web Service Architecture, Or you can write the processing logic from the beginning. Figure 1 shows the path used by the ASP. NET Request.
Miissues0311aspcolumnfig01

Figure 1 lifecycle of an ASP. NET Request

The ASP. net ui-processing architecture is centered on the web. UI. Page class (represented by An ASPX file. The aspx file can contain neat HTML code and server-side controls. When ASP. NET encounters a server-side control (through the "runat = server" attribute), it instantiates a class that represents the control (such as the button and ListBox controls ). Essentially, ASP. NET pages are processed as the tree of these server-side controls (the text and tags on this page are packaged as literalcontrol classes)-All others are server-side controls. When the page itself needs to be displayed, the page only traverses the control tree and each node on the "tell" tree shows itself. The operation method of the ATL server is somewhat different.
Back to Top
What is the difference between ATL server?

ATL Server is a C ++ template library used to create isapi dll. When creating IIS for the first time, developers must compile ISAPI extensions from the beginning or from the isapi dll class of MFC. To generate an isapi dll using the original C ++ or MFC code, you need to manually write the extension code. For example, mfc isapi does not provide a form-based architecture for developers. Any HTML Tag that ends on the client must be manually issued.

ATL server combines form-based methods with runtime speed and C ++ flexibility. A web site built using the ATL server consists of three basic components: Server Response file (SRF), application DLL, and necessary ISAPI extensions. SRF is a new type of file installed by ATL server in IIS. SRF ing directs IIS to the isapi dll of the application, which in turn points processing to one or more application DLL. SRF includes a special new markup syntax, which is essentially an entry point for calling in application DLL. Figure 2 shows the path used for system-based requests based on the ATL server.
Miissues0311aspcolumnfig02

Figure 2 Request Path Based on ATL Server

The ATL server application consists of many DLL (ISAPI extension and application extension) and HTML generation templates called SRF (as mentioned earlier. This architecture clearly separates application representations from application logic. The representation of a webpage is defined by SRF containing HTML and special tags. These tags call the ATL server application DLL.

Because most web applications use Windows as the target platform, the ATL server application must be built on isapi dll. The ATL server project contains a single ISAPI extension DLL that can process rough requests. The ATL server application also contains one or more application DLL for processing multiple precise requests. The request processing class is derived from crequesthandlert and contains your own unique code used to process the Code marked in SRF.

These handler classes include dictionaries that associate the request handler class with the request handler DLL and that associate the substitution method with the SRF flag. In addition to the dictionary substitution, crequesthandlert also contains methods and member variables for accessing standard web application elements, such as form variables, cookies, request streams, and response streams.

When the browser finds the. srf url through HTTP, IIS knows to use the isapi dll of the ATL server application to open the site. The ATL server application then opens SRF and loads the DLL of the application (if they are not yet loaded ). The application then sends the request to the default request handler class, which analyzes the SRF to find a flag with a special mark. Each time a tag appears in the SRF, the application calls an alternative to a handler class in an application DLL. This method dynamically generates browser output. Figure 2 shows the request path through the ATL server application.
Back to Top
ATL server and ASP. NET

Although both ATL server and ASP. NET are based on the ISAPI architecture, they process requests very differently. To illustrate these differences, let's look at an application example that collects personal names and their (or her) Development preferences. I will explain how to develop the user interface and how to use the session status. In the next section of this column, I will examine some other functions (such as cache and browser capabilities) And how Web services work on each framework. Figure 3 compares the functions of the two frameworks.
Back to Top
Aspx file and SRF

ASP. NET and ATL server introduce 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 the aspx file, such a class is system. Web. UI. Page. This page class is used to present Web Pages Based on the UI. Figure 4 shows a simple aspx file.

The main thing to note about the aspx file is the inheritance commands near the top of the page, as well as the "runat = server" attribute marked by buttons, labels, and drop-down lists. These labels indicate the classes corresponding to the server-side control in the code hidden file in Visual Studio.

In contrast, SRF contains the most standard and common HTML Tag. The ATL server does not have a server-side component architecture. However, it does introduce the concept of server response tag. These special tags are represented by double braces. When the ATL Server Request Architecture encounters a server response flag, it expects to find a corresponding handler function in the application DLL öð. Figure 5 shows a simple SRF. Its user interface is roughly the same as that shown in Figure 4 Aspx.

The most important thing to note in this document is the special mark enclosed by double braces. For example, near the top of the SRF, you will see the handler tag ({handler...}) of the default handler for the specified application ...}}). This will tell the ATL server application which DLL to load to find the function called by the response tag. Other response markers indicate the entry points in the application DLL.
Back to Top
"Inherent" Object

ASP. both net and ATL server contain similar inherent request and response objects, which are similar to the typical ASP protocol.. Net, which are represented by the httprequest and httpresponse classes. In the ATL server, they are represented by the chttprequest and chttpresponse classes. In each framework, they have the same purpose. The request object encapsulates items such as Request Parameters and request URLs. The response object can output text to the client. For example, to insert "Hello World" to an output stream based on an ASP. NET Request, you only need to call response. Write, as shown below:

Protected void helloworld ()
{
Response. Write ("Hello World ");
}

To output "Hello World" to a client based on the ATL server application, use the chttpresponse object as follows:

[Tag_name (name = "hello")]
Http_code onhello (void ){
M_httpresponse <"Hello world! ";
Return http_success;
}

Note how to call the onhello function by using the server response tag in Figure 5. (The mark is as follows: Hello .)
Back to Top
Manage UI elements

Each framework uses different methods to manage UI elements. As previously mentioned, the UI in ASP. NET supports the server-side control model. Indicates that the Code (aspx file) uses the "runat = server" attribute to declare the server element on the webpage. You only need to declare the corresponding class in the Code hiding class, and it is easy to access the control programmatically. For example, the Code in Figure 4 illustrates several server-side control elements (such as the submit button, text box element, and drop-down list ). The Code hiding page declares the button, Textbox, and dropdownlist classes as members of the page, allowing you to program these UI elements. To find the data in the textboxname element, you only need to access the text attribute, as shown below:

String S = This. textboxname. text;

ASP. NET Server-side controls also have the advantages of automatic view tracking. When the browser accesses the server back and forth, the UI elements (as shown in the following drop-down list box and single-choice button) will remain consistent. For example, the last item selected in the drop-down list box is the displayed item. You do not need to write any special code to ensure that the control behavior is correct.

The ATL server does not have such a control model. You can manage the UI only by using the server response tag. To fill in the drop-down list, a server response function is used in the ATL server example to fill it out (see the {showfeatureselection} mark in Figure 5. Figure 6 shows how the Server Response Function inserts items into the drop-down list.

The method of ATL server is different from that of ASP. NET. It does not track the view status. To maintain the consistency of the drop-down list, the code shown in Figure 6 is required. These codes check the input parameters of the query string and find out which one is selected. The rendering Code ensures that the selected item contains the "selected" attribute in the option tag.
Back to Top
Session Status

It is very convenient to manage session statuses in ASP. NET. The ASP. NET auxiliary process handles low-level details. When a new client starts a session, ASP. NET automatically allocates a dictionary containing name-value pairs. The system. Web. UI. Page class contains a reference to the current customer session information. To access the customer's status, you only need to use the indexer to access the session dictionary. Figure 7 shows the new session variables and the code needed to access them using ASP. NET in the future.

In the ATL server, session state management is a little complicated. Although an isapi dll is generated 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 generated by the ATL server wizard. Call this method at the beginning of each request, just like the init and load events contained in the ASP. NET page class. Validateandexchange is the session manager of isapi dll to obtain an interface (through queryservice ). If no session cookie exists in the title, this method creates a new session and adds a session cookie to the response. If this is the continuation of an existing Session, the Code uses the session information to fill in the name and age variables. Note that session variables are represented by com variables.
Back to Top
Summary

This month, I quickly browsed ASP. NET and ATL server. These frameworks represent the most advanced methods for pre-processing HTTP requests on Windows platforms. Each framework was built on a tested ISAPI architecture that appeared almost 10 years ago. ASP. NET and ATL server map their file extensions to specific DLL. ASP. net dll is aspnet_isapi.dll. The ATL Server DLL is generated by the ATL server, but for most of it, it is a code that can be applied repeatedly. In this regard, one advantage of the ATL server is that you can actually view (and change) the original ISAPI request processing code of special applications.

Although any framework can be used to write roughly equivalent applications, the standard issue needs to be considered here. Usually, it is very straightforward to Develop ASP. NET applications using a hosting language and ASP. NET Framework. However, you are subject to the Framework (although ASP. NET has mitigated the flexibility problem by using its scalability ). On the other hand, as long as the ATL server application passes the IIS test, it contains a high-performance recommendation for most of the DLL. The ATL server application is written in C ++, so you have many control rights and necessary responsibilities.

Next time, I will compare other functions of ASP. NET and ATL server, including buffer status, security, and Web services.
Figure 3 to figure 8 links: http://www.msdn.microsoft.com/msdnmag/issues/03/11/ASPColumn/default.aspx? Fig = true # fig3

George Shepherd specializes in the Development of. NET Framework software. He is the author of programming with Microsoft Visual C ++. Net (Microsoft Press, 2002) and co-author of applied. Net (Addison-Wesley, 2001. He taught developmentor at the seminar, and he was also an architect who contributed a lot to syncfusion's. Net tool.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.