Error control for Web sites (turn)

Source: Internet
Author: User
Tags contains error code error handling iis new features
web| Error | Control compiled as follows:

"Script error ... Debug Script ...? "or" type error ... "Such hints are part of the daily life of web developers. As a web developer, I know that it is almost impossible to anticipate all the errors that might be encountered and to deal with them so that users do not see the hints that are completely meaningless to them.

Instead, we can only accept the fact that errors can always occur at any time, and then come up with some way to control them subtly, which is what this article is about.

In this article, we will describe how you can respond to run-time errors caused by scripting, network, hardware, or other unexpected defects, and how to control these errors and what steps you can take to fix them.

The robust error control mechanism involves two aspects, the first is server-side error control, and the second is error control of client script in the browser.

Server-side error control

IIS 5.0 uses the ASP 3.0 scripting engine, which provides many new features to handle errors that may be encountered on the Web server. The ASPError object is one of the most noteworthy error handling objects introduced by ASP 3.0. For developers who are familiar with Vb/vbscript, the ASPError object is very similar to the Err object, but the former contains more information about the error.

IIS creates the ASPError object when it encounters an error in the execution of the script and populates the object with the following information and some other details:
ASPCode: An ASP error code returned by IIS.
Number: Contains a standard COM error code.
Source: Contains the actual code that generated the error.
File: The name of the ASP file that generated the error.
The line number in the Line:asp script.
Description: A short description of the error.




There is also a feature that already exists in IIS 4.0, but is enhanced in IIS 5.0, which is the ability to redirect all uncontrolled errors to the specified ASP page. If we use VB to compare, we can consider this function as "On Error Gogo" statement in VB, but the error control in VB only applies to specific functions, and error-oriented in IIS is valid for all ASP pages.

Examples of error control in Visual Basic functions are as follows:
Sub dosomething
On Error Goto ErrHandler <-(VB error control statement)
Code.....code ..... code .....
If A error occurs in the ' control ' is automatically
Transferred to the ErrHandler section below.
Code.....code ..... code .....
ErrHandler:
All errors come-here and hence-can be used to
Handle errors preventing the user from seeing them.
End Sub




Suppose the site has 50 Web pages, and if any one of the pages produces a run-time error, control automatically transfers to the specified ASP page. Here are the steps to set up error-handling pages:

In an MMC console (Windows NT) or IIS service (Windows 2000), the extension tree finds the Web site that you want to set up.
Right-click the Web site name display menu.
Click Properties.
In the Properties dialog box, select the custom error Message page.
Scroll through the list box to find the line where HTTP error appears as "500;100."
Double-click the row and select URL from the Message type list box.
Enter the URL of the page to be executed when the Web site encounters a run-time error in the URL input box.
Note: Enter the virtual path and do not enter the full URL. For example:
You can enter:
/mywebsite/tools/myerrorhandlingpage.asp
But do not enter:
Http://myServer/myWebSite/Tools/MyErrorHandlingPage.asp




Click OK to accept the settings and close the dialog box.
This enables the error-control features of the Web site. The next step in controlling the transfer to myerrorhandlingpage.asp will be based on the actual situation. Depending on the type of error, each site can handle them in a different way.



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.