ASP. NET is not a simple upgrade of asp, but Microsoft. It is an important part of the Net plan. Net multi-language and powerful class library support, introduced the Server HTML control and WEB control, automatic processing of control client and server interaction, it provides developers with a window programming interface similar to Windows, provides a good programming interface for developing large-scale network application functions, and greatly improves the efficiency of developers.
However, the "one conversion, two compilation" process makes the aspx file run for the first time after the first execution or update) slightly inadequate, especially in the application environment with a large number of code files aspx and codebehind, compile the aspx file into a DLL. . Net, called Application assembly) and then released, saving the time for "one conversion, one compilation" and CPU usage, greatly improving the overall performance of WEB Services. Of course, after being compiled into a DLL, the confidentiality of the source code is also improved to a certain extent.
This article through ASP. the basic processing process of NET and the analysis of an accidental secret are introduced in ASP. NET, how to establish aspx to DLL ing, how to develop a DLL that can handle HTTP requests/responses, and how to set "traps ", compile a single off-the-shelf aspx file and the codebehind aspx file into a DLL process. At the end of the article, I also introduced a small skill in the actual operation process.
This article involves ASP. NET application, web. config file. In order to make the reader better understand the content of this article, and to make this article not seem cumbersome, first introduce the system environment corresponding to this article:
System Environment: Win2000SP3) + IIS5 +. Net Framework 1.0 Chinese version ).
Server Name: as the examples in this article are all tested on the local machine, the server name is localhost.
IIS setting: Create the virtual directory dlltest with the actual path w: \ wwwroot \ dlltest), set it as an application, and create the bin directory under dlltest. All source files are stored in the dlltest directory, and all dll files are stored in the dlltest \ bin directory.
ASP. NET application configuration file-web. config creates a web. config file in the dlltest directory. The content of the file is as follows:
- <?xml version="1.0"?>
- <configuration>
- <system.web />
- </configuration>
-
Command window DOS window)
Open the command window and run the cd command to make the current directory w: \ wwwroot \ dlltest.
Create a asing from aspx to dll
First, let's take a look at how the aspx file is processed by ASP. NET in general:
When an HTTP request, such as "http: // webserver/webapp/webpage. aspx", is sent from the client to the IIS server, IIS captures and analyzes the request,
◆ When it analyzes that this request is An aspx page, it immediately calls asp.netruntime environment aspnet_wp.exe for "/webapp/webpage. aspx ),
◆ After the ASP. NET environment is started, check whether "/webapp/webpage. aspx" exists. If not, return the HTTP 404 File not found error to the client,
◆ Otherwise. find the corresponding dll file in the temporary directory of. NET. If the dll does not exist or is earlier than the aspx source file, call the csc compiler. If the server script language of aspx is VB or JScript, then, the corresponding vbc compiler and jsc compiler are called to compile the aspx file into a dll,
◆ ASP. NET then calls the dll to process the specific customer request and return the server response.
This process shows that ASP. the. NET runtime environment automatically identifies, checks, and updates the dll corresponding to the aspx. is there any other way to forcibly route the processing of An aspx file to a compiled DLL? In the httpHandlers section of the system. web section of the web. config file of the ASP. NET application configuration file, add the ing items from aspx to dll. The syntax is as follows:
- <Add Verb="*" Path="Aspx file name" Type="Class Name, dll file" />
Aspx file: Virtual name to be "routed". The extension must be aspx. Otherwise, IIS will process the file before the ASP. NET runtime environment.
Dll file: the name of the dll file application assembly. You do not need to enter ". dll ". ASP. NET first searches for the Assembly DLL in the dedicated \ bin directory of the application, and then searches for the Assembly DLL in the system assembly cache.
Class Name: because a dll may have multiple namespaces or classes, you must specify the class automatically loaded when the dll is called.
For example, the web. config file of an ASP. NET application is as follows:
- <?xml version="1.0"?>
- <configuration>
- <system.web>
- <httpHandlers>
- <add verb="*" path="index.aspx" type="BBS.IndexPage, bbs" />
- </httpHandlers>
- </system.web>
- </configuration>
The configuration file tells ASP. NET, in the client request the index of the application. when the aspx file is used, the bbs under the application bin directory is called directly. dll, and automatically load the BBS. indexPage class.