51NOD1819 Black and White Tree V2 [Tree Chain Section Seeking the Black Dot LCA and the Black and White Flip]


Design network server isapi

Reading this article requires basic knowledge of web/CGI, MFC, and Visual C ++ V4.1 or updated version.


For a long time, CGI has been a standard tool for interactive web development. The CGI script allows users to write simple applications in various languages, which runs on the network server and export directly to the user’s network browser. The user’s data inputs the device through the environment variable or standard input, and the program will return HTML text through the standard output. Such a simple design combines Perl and TCL language, which also makes CGIS very easy to use.

But CGIS also has a very big disadvantage: performance problems. Although there are many ways to make CGI run faster (for example: users can write CGI as compileable statements instead of Perl scripts), the speed is still the problem. Every time you enter the CGI, you have to go through the network. You can execute the CGI that you must create a new program for each time you enter the request. For a site with a large number of access, the above method is undoubtedly a huge burden on the server.

When Microsoft began to study their network server (MS IIS or IIS), realized that CGIS was the main problem for large network servers.

1. Enter isapi

In fact, Isapi uses DLL. The DLL used will be loaded into the server. The practice of cacheing the code into memory instead of the re -loading approach at once, the application of this technology is on the upward trend.

ISAPI’s advantages


In terms of function, this advantage is maximized.


ISAPI can create server filters. Completely integrated by MFC.

ISAPI Insurance


At present, there are only a few servers that support ISAPI

The simpleness of development


documentation is very small, and the process of debugging the program is relatively boring.
2, the basic knowledge of isapi

ISA is basically in the MFC ChTTPSERVER class. Chttpserver basically controls all the internal interaction of the server and includes 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 follows “


“name” and “ID” domain and related data have entered ISA, and the data must be placed in the database before use. To speed up ISAPI, the “MAPPING” system needs to be used.

“MAPPING” system also has other functions: ISAPI can guide the request to the dedicated functional area in ISA. The “request” string contains commands that can make the “MAPPING” system used to guide “requests” to an appropriate functional area.

Because ISAPI uses the “request” instructions, the ISA development system feels a bit slow. But as long as you master it, it is indeed a powerful tool for “request”.

Settings project

The first step to develop ISA is to establish a project work area. Just like other works areas founded by Visual C ++ (VC ++), work wizard guides users to complete the initial steps. Select New-Project Workspace, select “IsaPi Extension Wizard” as the project type, named “Hello Web”, and then click Create.

After completing the above steps, you will jump out of the dialog box to ask what type of ISA you are willing to create. The default settings have been configured for ISA, and MFC will dynamically pass the default connection. If your server is installed with MFCDLLS, the above steps are applicable. If not, the ISA will not run. If the project needs to be connected static. After completing the above steps, click “Completed”. Visual C ++ will remind you that the file is being created and the Chellowebextension will be generated. All the tasks in this article will be completed in Chellowebextent.

Now you have established a project, it’s time to complete some ISAPI development work. As mentioned earlier, ISA will become part of IIS when runtime. IIS runs in order like the NT server. This will complicate the debugging process. Because the VC ++ debugging system cannot control ISA, when the server is a service system. To solve this problem, Microsoft divides iIS into two parts, one is service, and the other is executable. Through executable parts, use the instruction line adjustable server. Although the problem has been solved and making development easier, the process of setting the above steps is a bit boring.

When you enter the debug part, in the user’s permission state, VC ++ (then IIS) runs under the user’s account. However, some of the users’ instructions cannot be entered but IIS must be executed, so users have to do the following steps:

Open the User Manager domain tool group (in the Administrative Tools Program Group)

Select User Rights in the Policies menu

Open Show Advanced User Rights column

Select ACT as part of the operating system in the list

Click the ADD button to pop up the ADD USERS and Group dialog box. Click the show used button to select the account you need. Then click ADD.

Repeat the same steps to generate the Generate Security Audits Rights.

The above steps are completed, please exit and log in again, so that the program takes effect.

IIS includes three services including FTP Publicish Service, Gopher Publishing Service, World Wide Web Publication Service. Once the debugging program runs IIS from the instruction line, the three services will stop running.

If the user wants to make a reasonable allocation of program debugging, it is best to turn off the IIS Service and use the Services Control Applets, and it is forbidden to automatically restart the function.

Once the service is closed, the project work area needs to be configured by the following steps

Select Settings from the Build menu

Click Debug tag and select “General Category”.

Type a position where you execute iIS

Type “-e W3SVC” in “Program Arguments” Field

Click Link tag.

Type the path and file name in “OUTPUT FILENAME” Field. The path will be displayed in the directory tree of the site, so it can be entered through URL. For example: your site root directory is C:/www/, and you put “HelloWeb.dll” in the root directory, so the URL will be:


Please exit and log in after the change settings.

The default settings generated by

The default settings generated by the ISAPI Extension guide include all details that compile ISA. Now you have completed the environment of the configuration debugging program, and now you can 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 of the program debugging, IIS will run in the background.


, enter the DLL URL into your favorite network browser and remember to add a question mark to the tail.

The URL will display the following:


The first time to connect to ISA will take a few seconds. But DLLS cache after execution, so the speed becomes stable.

After DLL login, 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 got a job of Isa

  Walking through the base code

When extension_control_block makes a request, it will be transmitted to the Command Parse Map. PARESE MAP is defined by a series of macro. As the code below is copied from the Hello Web project:

ISA has two main elements: PARSE MAP and Command Handler functions.

  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)


begin_parse_map marked the beginning of the PARSE MAP, and isa’s chttpserver and the base class chttpserver as the parameter.

on_parse_command_params () indicates that the instruction processor is a special request format or command. Its parameters are the class name and request format of the function of the function. Default_parse_command explains that function is called, and the parameter is called the class name.

Command Handler Functions is a member function of the main function chTTPSERVER class. PARESE MAP calls chttpserver through the get method. Below is the “default” instruction processing process of Hello Web:

void CHelloWebExtension::Default(CHttpServerContext* 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”);

When the request is empty or contains the function of “DEFAULT”, the request enters the program body through chttpservercontext. The first parameter must be a chttpservercontext object. StartContent () method is placed in PCTXT <html > <body>, and writetital () is a <Title> mark. The following three -line statements are written to the default message and pip PCTXT to ChtmlStream, and send it to the client after the ISA processing is completed.

   Hello Web 

The first program will replace the default information string with “Hello Web”.

Find the DEFAULT () member function in Chellowebextent Class, and change it according to the following way.

void CHelloWebExtension::Default(CHttpServerContext* pCtxt)

*pCtxt << _T(“Hello Web!”);

Create, run DLL and reload and replace DLL from the network browser

default information is:

  produced by the InternetServer DLL Wizard. Edit

  your CHelloWebExtension::Default() implementation to change it.

will be displayed:

  Hello Web!

If the “Server Error 500: Specified Module Not Found.” Tip, the project you created is a dynamic connection and lacks the necessary DLLS. To correct this error, you must re -connect the project with MFC.


Related Posts

ListView uses the getView problem NEO

python2 console shows garbled and saved file garbled Gu Ying

# Cross-Entropy (Cross Entropy) loss function chenglin

Unity3D —— Model Click events

51NOD1819 Black and White Tree V2 [Tree Chain Section Seeking the Black Dot LCA and the Black and White Flip]

Random Posts

SpringBoot and JWT integration

Simulation signal Discuss in-depth transmission distance of 4-20mA current signal

Android adds bitmap to the overlay of View

C ++ Exception Handling (abnormal processing) part1 The two most common errors in the

VC Thinking deeply: I have to say a business in business!