Recommended: Knowledge about advanced ASP Error objects for ASP application In VBScript, there is an OnErrorResumeNext statement that causes the script interpreter to ignore runtime errors and continue execution of the script code. Then the script can check the value of the Err.Number property to determine whether an error occurred. If an error occurs, a non-zero value is returned
4.2.3 Examples of server-side containing instructions
This section provides some sample pages that can be used to experiment with various server-side contained statements. Open the subdirectory of the sample web page Chapter04, displaying the SSI Directives and the ASP Server Object homepage (i.e. Default.asp in the subdirectory Chapter04)
All examples of this book can be downloaded from our web site. Readers will find all sample pages for the rest of this chapter in Chapter 04, the example subdirectory.
1. Use SSI/CGI to process instructions
Click the link to enter the Server-Side Include and CGI Statements page, which will open the ssi_cgi.stm page. It should be noted that the file extension of this page is .stm, indicating that this is not an ASP web page. This page uses all SSI instructions except the #exec instruction (which will be seen later) discussed earlier, and displays the usage methods and results of the instructions, as shown in Figure 4-4:
Figure 4-4 SSI/CGI processing instructions displayed on the example web page
(1)#include command
The beginning of the page Include Files with SSI, displays the contents of another separate file named intro.inc. Here is the full content of the file:
Note that we must use HTML entries < and > to display angle brackets in the web page. If they are not done, they cannot be treated as part of the annotation element and cause the instructions therein to be executed.
In the main ssi_cgi.stm page, the code to insert this file into the page is very simple:
<!-- #include file=intro.inc -->
(2)#config, #fsize and #flastmod directives
The next part of the page shows the size of the file Default.asp in the same directory as the page and the last time it was modified. The #config directive was used three times here:
· Once is the SSI error message set.
· Once is the format of date and time.
· Once set the format of file size calculation.
Use the #fsize and #fiastmod directives to insert the value into the web page:
<P><DIV CLASS=subhead>SSI Statements</DIV>
<!-- #config ERRMSG=SSI Processing Error -->
(sets error message in case of SSI error)<BR>
<!-- #config ERRMSG=SSI Processing Error --><P>
Details of file 'Default.asp':<BR>
<!-- #config SIZEFMT=BYTES -->
(sets fsize to return size in bytes)<BR>
<!-- #config SIZEFMT=BYTES -->
<!-- #fsize FILE=Default.asp -->
returns: <B><!-- #fsize FILE=Default.asp --> bytes</B><BR>
<!-- #config TIMEFMT=%A, %B %d %Y %H:%M:%S -->
(sets format for date/time results)<BR>
<!-- #config TIMEFMT=%A, %B %d %Y %H:%M:%S -->
<!-- #flastmod FILE=Default.asp -->
returns: <B><!-- #flastmod file=Default.asp --></B><P>
(3)#echo command
The last part of the page (only a portion can be seen on the screen) shows the contents of all HTTP headers that can be accessed using the #echo directive. The code in each line is the same, except that the VAR property value changes. A complete list of all allowed values for the VAR attribute is given in Appendix G.
<DIV CLASS=subhead>HTTP Variables</DIV>
<!-- #echo VAR=AUTH_TYPE -->
returns: <B><!-- #echo var=AUTH_TYPE --></B><BR>
<!-- #echo VAR=AUTH_PASSWORD -->
returns: <B><!-- #echo var=AUTH_PASSWORD --></B><BR>
… etc…
2. Use the #exec directive
The #exec directive is more difficult to use than other SSI directives, and because of this, it is placed independently on another page. The startup page can be accessed from the ASP Server Object and SSI Directives main menu.
On this page, select the Using the #echo Server-Side Include Directive link. This operation opens the SSI #exec Directive page
The SSI #exec Directive Web Page
This is an ASP web page ssi_exec.asp. Two buttons are used to open the .stm page, which performs the actions described in the #exec directive.
(1) Run this example on the server
Before the SSI #exec directive example can work on the server, some configurations must be modified. First, you need to create an SSIEnableCmdDirective entry (type DWORD) in the registry of the web server, with the location below the key name:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/W3SVC/Parameters
Then set the value to 1
This allows the #exec directive to be used with the CMD attribute.
Secondly, anonymous access must be prohibited for directories containing .stm files using the #exec directive. The client will be forced to provide details of the account, which should be an account with administrator-level permissions. This is also a requirement for the net command to work normally.
Activate the Internet Services Manager application and select the directory containing the .stm files using the #exec directive (in the example, these files are start_cisvc.stm and stop_cisvc.stm in the exec directory). Then open the Properties dialog box for that directory. Click the Edit button in the Anonymous access and authentication control area in the Directory Security tab to open the Authentication Methods dialog box
The Anonymous access check box is not selected in this dialog box. If you do not use Internet Explorer to access the page, open the Basic authentication option to allow non-IE browsers to access the page by submitting username/password. When setting up, a warning about security appears, click Yes. The browser will now be forced to show the appropriate account and identity certificate because the page cannot be accessed anonymously.
In order to see the results of starting and terminating the service, open the Services MMC plug-in and terminate the Indexing Service
(2) Start and terminate Indexing Service
Click the button on the sample web page to start the Microsoft Indexing Service.
The short name of this service is cisvc, which is commonly called Microsoft Index Server, and the ci character in the name actually represents the content indexer.
When prompted, enter the username and password of an account with administrator privileges on the web server. When the page (start_cisvc.stm) is opened, you will feel a certain delay because the #exec directive loads an instance of the window command interpreter (cmd.exe) and then executes the net start command. Once the service starts (or if it is already running), the rest of the page will be displayed
The interface displayed after entering the username and password
The code for this page is very simple. You can see that the #exec directive has a CMD property, which is set to cmd.exe /c net start cisvc. The form contains the SUBMIT button to return to the previous page:
<P>Processing the SSI directive:</P>
<P><B><!-- #exec CMD=cmd.exe /c net stop cisvc --></B></P>
<!-- #exec CMD=cmd.exe /c net stop cisvc -->
<FORM ACTION=../ssi_exec.asp>
<INPUT TYPE=SUBMIT NAME=cmdOK VALUE= >
Return to the previous page<P>
</FORM>
You can open other .stm web pages from the previous page, such as stop_cisvc.stm, to terminate the service again, the only difference is that the net stop command is used instead of the net start command.
…
<!-- #exec CMD=cmd.exe /c net stop cisvc -->
…
Share: Example explains how to use the disconnect record set in ASP When we use ASP's built-in ADO components for database programming, we usually open a connection at the beginning of the script and close it at the end of the script, but for larger scripts, the connection is open much longer in most cases than it needs to be opened. Therefore