ATLServer and ASP. NET

Source: Internet
Author: User
Tags what is asp
Article title: ATLServer and ASP. NET. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
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.
    
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.
  
   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.
  
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.
  
   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.
  
   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.
  
   "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 .)
  
   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, one
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.