Recommended: ASP.NET method to obtain IP and MAC address The method of obtaining the server's IP address is simple and practical to use DNS method, as follows: private void ButtonIP_Click(object sender, System.EventArgs e){ System m.Net.IPAddress[] addressList = Dns.GetHostByName(Dns
7.4.4 Using IIS Error Page
What is related to the ASP error handling process is to provide IIS with customizable error pages. In fact, this feature is also found in IIS 4.0. But the new ASP built-in object ASPError is easier to use and provides more powerful features.
In Chapter 4, when we look at the Server.Execute and Server.Transfer methods, we have already talked about how to create a customized error page. We also discussed and used the ASPError object, but this method is subject to certain limitations. In this section, we will introduce how to combine a customized error page with an ASPError object to create a better way to handle ASP errors.
We can use VBScript to check the contents of the ASPError object, thereby creating a custom error page. Build a string containing comprehensive information about the error content and write it to a log file on the server disk. However, it is not possible to design a web page to only make the visitor see that the web page is not available. It should allow visitors to choose whether to reload the previous web page or return to the home page, so that they are unaware that an error has occurred.
Although we use VBScript to create this web page, some of the features it uses are also applicable to JScript, and it is also easier to convert the two scripting languages.
Sample files for this chapter and other chapters of this book can be downloaded from the http://www.wrox.com site.
1. Setting up custom error pages
Before you can use a customized error page, you must make the corresponding settings in the Internet Services Manager (see Chapter 4 for setting up methods). Load the sample file into the wwwroot directory of the computer, open the Properties dialog box of the Chapter07 subdirectory, in the Custom Errors tab, scroll the list and select the HTTP Error 500:100 entry, click the Edit Properties button, and type the URL of the customized error page Custom_error.asp
Now when an ASP error occurs on the page in Chapter07 subdirectory, the customized error page will be opened.
2. Use custom error page
Open the Chapter07 directory in your browser and select the link to Using a Custom Error Page. This page displays a series of buttons for generating various types of errors. Click the button marked Load a Page with a Syntax error
This will load a simple page called syntax_error.asp. However, this page cannot be seen because this page contains a syntax error. ASP terminates the compilation/execution of this page and transfers the execution to the custom error page. This page displays the details of the error and two buttons, which are used to return to the previous page (main menu) or to return to the default home page of the Web site.
This page also appends the error report to the log file named custom_error.log in the server disk C:/temp folder. It can be opened and viewed in the file editor. The log file has recorded several errors.
If you get a message in the page, indicating that the log file cannot be written, it may be because the IUSR_machinename (IUSR_computer name) account does not have permission to access the C:/temp directory. When testing this page, the IUSR_machinename account should be given all control over this directory, or the program code of the custom_error.asp page should be changed to point to a folder where IUSR has full control.
The only reason why the error message appears in the page is because in the cause_error.asp page we selected the corresponding checkbox. If you turn off this option and click the button again, you will not see the details of the error, but the error message is still recorded in the custom_error.log error log file on the server disk.
The Display debugging information check box gives custom error pages (rather than log files) more information and helps debug pages that use ASP built-in object collection values.
This issue will be discussed later in the following section of this chapter, and you can also learn about other types of error information provided by other buttons on the Cause An Error page. Note that some buttons can provide more information than others. In particular, only the last button gives the value of the ASP error code (here is ASP 0177).
(1) Functions of Cause An Error page
As with the example pages discussed earlier, the pages that cause the error use the same technique, using <Form> to submit the value to the same page. Then click the SUBMIT button on the ASP program viewing window, and then run the corresponding part of the code. Also check whether the two check boxes on the page are selected. If so, the program first sets one or two session-level variables to indicate this.
<%
'see if we are displaying error and debug information
'set session variables to retrieve in the custom error page
If Len(Request.Form(chkShowError)) Then
Session(ShowError) = Yes
Else
Session(ShowError) =
End If
If Len(Request.Form(chkShowDebug)) Then
Session(ShowDebug) = Yes
Else
Session(ShowDebug) =
End If
...
%>
Because of the use of Server.Transfer, when an error occurs, the entire ASP environment of the running web page is passed to the custom error page by IIS. However, the value of the script variable is not passed to the custom error page, so the Session variable must be used, or the value must be added to the Request.Form or Request.QueryString collection in order to pass the value to the custom error page.
After setting the Session variable, the program continues to view which button has been clicked. Each type of error (except the first type) is generated by running the corresponding ASP code, and the first type of error requires calling another page.
...
'look for a command sent from the FORM section buttons
If Len(Request.Form(cmdSyntax)) Then
Response.Clear
Response.Redirect syntax_error.asp
End If
If Len(Request.Form(cmdParamType)) Then
intDate = error
intDay = Day(intDate)
End If
If Len(Request.Form(cmdArray)) Then
Dim arrThis(3)
arrThis(4) = Causes an error
End If
If Len(Request.Form(cmdFile)) Then
Set objFSO = Server.CreateObject(Scripting.FileSystemObject)
Set objTStream = objFSO.OpenTextFile(does_not_exist.txt)
End If
If Len(Request.Form(cmdPageCount)) Then
Set objPageCount = Server.CreateObject(MSWC.PageCounter)
objPageCount.WrongProperty = 10
End If
If Len(Request.Form(cmdObject)) Then
Set objThis = Server.CreateObject(Doesnot.Exist)
End If
Share: Finally found a solution to cross the boundary of ASP subscript Yesterday, my movie website had a problem when generating static content pages. It was prompted to cross the line with the subscript. I had never encountered it before, so I didn't know what it was, so I looked for answers online, but it was really hard to find. I found a lot but couldn't solve the fundamental problem.