Read this article requires basic Web / CGI, MFC, and Visual C V4.1 or update version. ISAPI and CGI have long been a standard tool for interactive web development. The CGI script allows users to write simple applications with various languages, which run on the web server and output directly to the user's web browser. The user's data is entered by an environment variable or a standard input device, and the program returns an HTML text through the standard output. Such a simple design combines the PERL and TCL language, making CGIS very easy to use. But CGIS also has a very large disadvantage: performance problem. Although there are many ways to make CGIs run faster (for example: users can write CGI to executable compileable statements, rather than Perl scripts), but speed is still a problem. Every time you enter CGI, you have to pass the network, you can perform CGIs that must create new programs for each entry request. For a large site, the above method is undoubtedly a huge burden for the server. When Microsoft began to study their web server (MS IIS or IIS), it is a major problem with CGIS for large web servers. 1. In fact, ISAPI uses DLL in fact. The DLL used will be loaded into the server. The code cache into memory replaces the approach to reloading once, the application of this technology is in the utmost trend. The advantages of ISAPI have the greatest embodiment of this advantage. Features ISAPI can create a server filter. Integrate completely from MFC. The shortcoming of ISAPI is currently only a few servers support ISAPI development very little document, and the process of debugging is boring. Second, ISAPI's basic knowledge ISA is basically the MFC Chttpserver category, and ChttpServer basically controls all server interactions and contains all the functions required by the user. In fact ISA can handle a large number of similar requests. Therefore, ChttpServer creates ChttpServerContext for each request. ChttpServerContext includes all professional data and all HTML. ISAPI DLLS is developed by the needs of users, and the usage is similar to CGI. As described in the following example "http://www.mysite.com/myisa.dll?name=bob&id=15248" Name "and" ID "fields and related data have entered ISA, and the data must be placed in the data inventory before use To speed up ISAPI, you need to use the "mapping" system. "Mapping" system also has other functions: ISAPI can boot request to the dedicated ribbon within ISA. "Request", contains the "mapping" system to boot "Request" to the appropriate ribbon command. Because ISAPI uses the "request" instruction, the ISA development system will feel a bit sluggish. But once the master is, it is indeed a powerful tool that handles "request". The first step in setting the project development ISA is to create a project work area. Just like other workspaces created by Visual C (VC ), the work wizard boots the user to complete the initial step. Select New-Project Workspace, select "Isapi Extension Wizard" As the type of item, name "Hello Web", then click Create. After completing the above steps, the dialog will be jumped out of the dialog asking you what type of ISA is willing to create. The default setting has been configured for ISA, the MFC will dynamically pass the default connection.
If your server is already installed, the above steps apply, if it is not, ISA will not run. If the project needs a static connection. After completing the above steps, click "Finish". Visual C will remind you that file is created and generate chellowebextension. All the work in this article will be completed in the chellowebextension. Now you have established a project, it is time to complete some ISAPI development work. As early as possible, ISA will become part of IIS.. The operation is like the NT server. This makes the debugging process complicated. Because the VC debugging system cannot control ISA, when the server is used as a service system, in order to solve this problem, Microsoft divides IIS into two Some, one is service, and the other is executable. By executable part, the command line can adjust the server. Although the problem is solved and makes the development easier, the process of setting the above steps is a bit boring When you enter the debug part, in the allowable state of the user, VC (then IIS) will run under the user's account. However, some are the user's instructions do not enter the part of IIS, so the user Go to the following steps: Open the User Manager domain toolbar (in the Administrative Tools Program Group) Select User Rights in the Policies menu to open the SHOW Advanced User Rights column Select AS Part of the Operating System in the right list to pop up Add Users and Groups dialog. Click the Show Users button to select the account you need. Then click Add. Repeat the same steps to generate the generate security audits Rights. Please exit after the step is completed, so that the program takes effect. IIS contains FTP Publishing Service, Gopher Publishing Service, World Wide Web Publishing Service, etc. Once the debugger runs IIS from the instruction line, three services will stop running. If the user wants to make the program debugging, it is best to turn off IIS. Service, turn to the Services Control Applet, and disable automatic restart. Once the service is closed, the project workspace needs to be configured in the following steps to select Settings Click the debug tab and select "General Category". in "Executable Type IIS in the For Debug Session "field in" Program Argumen " Type "-e W3SVC" in TS "field" Click the Link tab. Type a path and file name in the "Output FileName" field. The path will be displayed in the directory tree of the site, so you can enter it through the URL. For example: your site root directory is C: / www /, and you will "HelloWeb.dll" in the root directory, so the URL will be: http://www.mysite.com/helloweb.dll Please change After setting, you quit login and log in. The default settings generated by the ISAPI Extension wizard include all details of compiling ISAs. Now you have completed the environment of the configuration debugger, you can now create and run the project. Press F5 to open the ISA, when the system is asked if the project is established, press YES.
After a few seconds created in program debugging, IIS will run in the background. After entering your DLL's URL, you can remember to join a question mark at the end. Then the URL will appear as follows: http://www.mysite.com/helloweb.dll? The first connection to ISA will spend a few seconds. However, DLLS will be cached after execution, so speed becomes stable. After the DLL is logged in, the following information will be displayed: This Default Message Was Produced by The Internet Server DLL Wizard. Edit Your Chellowebextension :: Default () Implementation To change It. Now you have a work ISA WALKING THROUGH THE BASE CODE When Extension_Control_block makes a request, it will be sent to Command Parse Map.. PARSE MAP is defined by a series of macros, as the code mentioned below is copy from the Hello Web project: ISA has two main elements: Parse Map and Command Handler features. BEGIN_PARSE_MAP (CHelloWebExtension, CHttpServer) // TODO: insert your ON_PARSE_COMMAND () and // ON_PARSE_COMMAND_PARAMS () here to hook up your commands // For example:. ON_PARSE_COMMAND (Default, CHelloWebExtension, ITS_EMPTY) DEFAULT_PARSE_COMMAND (Default, CHelloWebExtension) END_PARSE_MAP (CHelloWebExtension Begin_parse_map label the start of PARSE MAP, ISA's Chttpserver, and base class Chttpserver as a parameter. ON_PARSE_COMMAND_PARAMS () indicates that the instruction processor is a special request format or command, and its parameter is the class name and request format of the functionality. Default_parse_command Description That function is called, the parameter is the class name called. Command Handler Functions is a member function of the primary function chttpserver class, and Parse Map calls ChttpServer through the GET method. Here is the Hello Web "Default" command handler: void CHelloWebExtension :: Default (CHttpServerContext * pCtxt) {StartContent (pCtxt); WriteTitle (pCtxt); * pCtxt << _T ( "This default message was produced by the Internet "); * PCTXT << _t (" Server DLL Wizard. Edit Your Chellowebextension :: Default () "); * PCTXT << _t (" Implementation to change it./r/n" );ndContent (PCTXT);
When the request is empty or contains the "default" function called, the first parameter must be a chttpsercontext object via ChttpServerContext. The first parameter must be a chttpserverContext object. The startContent () method places
in PCTXT, WriteTitle () is placedThe first program will replace the provincial strings in "Hello Web".
Find the Default () member function in the ChelloweBextension Class, and change it in the way below.
Void chellowebextension :: default (chttpserverContext * PCTXT) {startcontent (PCTXT); WRITTITE (PCTXT); * PCTXT << _t ("Hello Web!"); endContent (PCTXT);
Create, run the DLL and reload from the web browser and replace DLL
The default information is:
Produced by the InternetServer DLL Wizard. Edit
Your chellowebextension :: default () Implement to change it.
Will be displayed:
Hello Web!
If "Server Error 500: Specified Module Not found." Prompts, the items you create are dynamically connected, and the necessary DLLs are missing. Correct this error, you must use the MFC to re-static connection items.