Compile the ASPX file into a DLL file No. 148 Jiefang North Road, Zhejiang Province, Jiejun 2002-11-12 14:39:19
Preface ASP.NET is not an Asp's simple upgrade, but an important part of the Microsoft .NET plan, which relies on .NET's multilingual and powerful library support, introduced the server HTML control and web control, automatic processing control The client interacts with the server provides developers with interface programming similar to Windows, providing a good programming interface for developing large network application functions, and can greatly improve developers' work efficiency. However, "One Transfer, Two Compilation" procedures makes the ASPX files in the first execution (or updated first run), especially in an application environment with a large number of ASPX and codebehind, put the ASPX file After the DLL (in .NET, known as the application set), release, saving the time and CPU usage of "one transition, one compilation", and the overall performance of the Web service will have a large increase. Of course, after compiling into a DLL, the confidentiality of the source code has a certain degree. This article introduces how to establish an ASPX to DLL mapping in ASP.NET through the basic processing flow of ASP.NET, how to establish an ASPX to DLL map, how to develop a DLL that can handle HTTP request / response, and how to set up Trap ", compiling the ready-made single ASPX file with codebehind's ASPX file into a DLL process, and the article is finally introduced to a small skill in the actual operation process. Since this paper should involve the ASP.NET application, the command line compilation, web.config configuration file, etc. In order to make the reader better understand the content of this paper, in order to make this article, the system will correspond to the system corresponding to this article An Introduction: System Environment: WIN2000 (SP3) IIS5 .NET Framework 1.0 (Chinese version). Server Name: Since the examples of this article are tested on this machine, the server name is LocalHost. IIS setting: Create a virtual directory DLLTEST (the real path is w: / wwwroot / dlltest) and set it to the application, and establish a bin directory under Dlltest. All source files will be placed in the DLLTEST directory, and all DLL files will be placed in the DLLTest / bin directory. ASP.NET Application Profile --Web.config creates a web.config file in the dlltest directory, the contents of the file are as follows: XML Version = "1.0"?>
First, the mapping of the ASPX to DLL first let us take a look at how the ASPX file is processed by ASP.NET: when an HTTP request (such as "http: //webserver/webapp/webpage.aspx") from customers When the end is sent to the IIS server, IIS captures and analyzes this request. When it analyzes this request is an ASPX page, immediately call the ASP.NET running environment (ASPNET_WP.EXE) as the "/webapp/webpage.aspx", After the ASP.NET environment is started, check "/webapp/webpage.aspx" does not exist, if there is no existence, return to the client back to the HTTP 404 (File Not Found) error, otherwise look up the corresponding DLL in the temporary directory of ASP.NET. File, if there is no existence or the DLL is "old" than the ASPX source file, call the CSC compiler (if the ASPX server scripting language is VB or JScript, call the corresponding VBC compiler, JSC compiler) to compile the ASPX file Being a DLL, then ASP.NET calls the DLL to handle the specific customer request and return to the server response. As can be seen from this processing process, in general, the ASP.NET running environment automatically recognizes, checks, updates DLL corresponding to ASPX. So do you have any other way to force the process of processing a ASPX file to a DLL that has been compiled? The method is to add ASPX to DLL mapping items to the Httphandlers section of the ASP.NET application configuration file Web.config, the syntax is as follows:
Let's take a look at Microsoft ASP.NET Quick Start Tutorial (http://chs.gotdotnet.com/quickstart/aspplus/) About "HTTP Processor and Factory" description: ASP.NET provides low-level request / response API Make developers to provide services using the .NET framework class as incoming HTTP requests. To this end, developers need to create classes that support the System.Web.ihttPHandler interface and implement the processRequest () method. The handler is usually useful when processing HTTP requests do not require services provided by a high-level page framework. The common use of the handler includes filters and applications similar to CGI, especially those that return binary data. Each incoming HTTP request received by ASP.NET is finally processed by a specific instance of the class that implements the IHTTPHANDLER. IHTTPHandlerFactory provides the actual parsing of the IHTTPHANDLER instance URL request. In addition to the default IHTTPHandlerFactory class provided by ASP.NET, developers can also choose to create and register factories to support a large number of request parsing and activation. As can be seen from this text, when the ASPX page does not involve the advanced interface technology provided by the .NET framework (such as data cache, status, web form control reference, etc.), and output to the client is not a complex HTML text. In particular, when binary data (such as pictures, sounds, etc.) is returned to the client, can be used in a .cs application file (this article uses the C # language, if it is used in VB or JScript, ...), The program must have a class that implements the System.Web.ihttPHandler interface and and implements the processRequest () method. A simple example is as follows: / * Source file: EX1.CS start * / using system.Web; Namespace DLLTEST {/ * class must implement the IHTTPHANDLER interface. If the program will access a session status (Session), you must implement the IREQUIRESSESSITIONSTATE interface (not containing tag interfaces for any method). * / public class ex1page: IHTTPHANDAL {/ * isreusable property tells the .NET framework, whether the program can be used simultaneously by multiple threads. TRUE corresponds to whether false is right. * / public bool isreusable {get {return true;}} / * Implement the ProcessRequest method to return response data to the client. In this example, return a simple HTML page to the client * / public void processRequest (httpresponse res = context.respResponse; res.write ("
"); res.write ("CSC / T: library /out :bin/ex1.dll ex1.cs Add ASPX-> DLL mapping in the configuration file web.config, after adding, web.config should be like this: XML Version = "1.0" ?>