ASP 3.0 Advanced Programming (15)

Source: Internet
Author: User
Tags object error code error handling iis string window client
Programming | error handling for advanced 4.3.4 server objects
The ASP has been criticized for not having error-handling mechanisms.
In VBScript, there is an on Error Resume Next statement that causes the script interpreter to ignore Run-time errors and continue the execution of script code. The script can then check the value of the Err.Number property to determine if an error has occurred. If an error occurs, returns a value other than 0. In ASP 3.0, you can also use On Error Goto 0 to "go back" to the default fault handling. This process is actually done in ASP 2.0, but there are no documentation instructions.
In JScript, there is a new error-handling feature: C-language-style try and catch statements. However, none of these error-handling techniques are implemented by ASP or IIS, but by the scripting engine used by ASP.
The 7th chapter is devoted to debugging and error-handling techniques involved in scripting and scripting engines.
At the same time, the ASP and IIS development teams have added a new feature for error handling in ASP Web pages. This is divided into two parts: the configuration of the IIS error page and a new method and object for using ASP.
1. GetLastError method for the server object
In ASP 3.0, the server object has a new method named GetLastError. Unlike the Err object in VBScript, the method cannot be invoked at any time to see if an error occurs, but can only be used in an ASP-customized error Web page. If, as with the Err object, the GetLastError method cannot access the details of the error by turning off the default error handling (with the On Error Resume Next statement).
The GetLastError method is to provide more information about the source of the error and the cause of the error. The GetLastError method creates and returns a reference to an object that is a new object named ASPError. This object has a series of properties that return information about the most recent error that occurred before the GetLastError method call.
2. Properties of the ASPError object
The ASPError object provides nine properties that describe the nature and source of the error that occurred, and returns the actual code that caused the error, whose properties and descriptions are shown in table 4-4:
Table 4-4 Properties and descriptions of ASPError objects
Property
Description

ASPCode
Integral type. The error number produced by Asp/iis, such as 0x800a009

ASPDescription
String type. If this error is an ASP-related error, this property is a detailed description of the error

Category
String type. The source of the error, that is, the ASP internal scripting language, or an object

Column
Integral type. The character position in the file where the error occurred

Description
String type. Short description of the error

File
String type. The name of the file being processed when the error occurred

Line
Integral type. The line number in the file that generated the error

Number
Integral type. A standard COM error code

Source
String type. Actual code of the row that raised the error

3. Configure single page error handling
When an error occurs "Strangely" in IIS (for example, 404 Not Found), the page looks like an error message page that is returned from the server to the client, but in fact it is not. They are normal HTML pages that are downloaded and sent to the client when responding to an error. These web pages are often called custom error pages (custom errors page).
However, the error Web page is the default installation part of IIS and can be customized on request. In fact, you can also create custom error pages in earlier versions of IIS.
In IIS 4.0, you can specify a custom error page for each different type of HTTP protocol or server error, and a custom error message page for each directory in any Web site on the server.
(1) IIS default error Web page
The default error page provided by IIS is placed in the Winnt\Help directory of the Web server. In the context of IIS 5.0 in Windows 2000, the page is placed in the Winnt\help\iishelp\common directory, as shown in Figure 4-17:

Figure 4-17 The default error page location
You can open these files to view the results in a browser, or view the HTML source and script code in a text editor. When a 404 error occurs, the page used is 404b.htm, which contains a portion of the client-side scripting code that obtains the URL of the current document (retrieved from the URL property of the Document object) and displays it on the page:
<tr>
&LT;TD width= "colspan=" 2 "> <font style=" color:000000; font:9pt/11pt "> The page you are searching for may have been deleted, renamed, or temporarily unavailable. </font></td>
</tr>

<tr>
&LT;TD width= "colspan=" 2 "> <font style=" color:000000; font:9pt/11pt Song Body ">


<p> Please try the following actions:</p>

<ul>
<li> If you type the address of the Web page in the Address field, check that it is spelled correctly. <br>
</li>

<li> Open <script>
<!--
if (!) ( (Window.navigator.userAgent.indexOf ("MSIE") > 0) && (window.navigator.appVersion.charAt (0) = = "2"))
{
Homepage ();
}
-->
</script> homepage for a link to the information you want. </li>
...
<script>
function homepage () {
<!--
Docurl = document. URL;
Protocolindex=docurl.indexof ("://", 4);
Serverindex=docurl.indexof ("/", Protocolindex + 3);
Beginurl=docurl.indexof ("#", 1) + 1;
Urlresult=docurl.substring (Beginurl,serverindex);
Displayresult=docurl.substring (Protocolindex + 3, serverindex);
document.write (' <a href= ' + urlresult + ' "> ' + displayresult +" </a> ");
}
-->
</script>
This produces the page you often see, as shown in Figure 4-18:

Figure 4-18 page when 404 error is generated
(2) Mapping of error pages in IIS
When IIS detects an error, the corresponding error page is routed to the client. How to identify which page should be sent to the client? Obviously, the name of the Web page should have some information to solve the problem, but the fact that the filename is not important. Error and error The mapping relationship between the page files is determined in the Custom Errors tab of the Properties dialog box for each directory.
In Internet Services Manager, right-click the directory where you want to edit the mapping relationship, and select Properties. If you set the sample file, select the server subdirectory in the Chapter04 directory, as shown in Figure 4-19:

Figure 4-19 the page screen when setting properties
The Custom Errors tab of the Properties dialog box sets a list of default mapping relationships when IIS is installed (unless modifications have been made), as shown in Figure 4-20



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.