[摘要]help\common\404b.htm 這個檔案放置的內容就是在描述當所查詢的網址不存在時會發生的錯誤訊息,404b.htm的原始檔如下: 404b.htm &l...
help\common\404b.htm
這個檔案放置的內容就是在描述當所查詢的網址不存在時會發生的錯誤訊息,404b.htm的原始檔如下:
404b.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<style>
a:link {font:9pt/12pt 新細明體; color:red}
a:visited {font:9pt/12pt 新細明體; color:#4e4e4e}
</style>
<meta HTTP-EQUIV="Content-Type" Content="text-html; charset=big5">
<title>HTTP 404 找不到</title>
</head>
<script>
function Homepage(){
// in real bits, urls get returned to our script like this:
// res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm
//For testing use DocURL = "res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm"
DocURL = document.location.href;
//this is where the http or https will be, as found by searching for :// but skipping the res://
protocolIndex=DocURL.indexOf("://",4);
//this finds the ending slash for the domain server
serverIndex=DocURL.indexOf("/",protocolIndex + 3);
//for the href, we need a valid URL to the domain. We search for the # symbol to find the beginning
//of the true URL, and add 1 to skip it - this is the BeginURL value. We use serverIndex as the end marker.
//urlresult=DocURL.substring(protocolIndex - 4,serverIndex);
BeginURL=DocURL.indexOf("#",1) + 1;
if (protocolIndex - BeginURL > 7)
urlresult=""
urlresult=DocURL.substring(BeginURL,serverIndex);
//for display, we need to skip after http://, and go to the next slash
displayresult=DocURL.substring(protocolIndex + 3 ,serverIndex);
// Security precaution: must filter out "urlResult" and "displayresult"
forbiddenChars = new RegExp("[<>\'\"]", "g"); // Global search/replace
urlresult = urlresult.replace(forbiddenChars, "");
displayresult = displayresult.replace(forbiddenChars, "");
document.write('<A target=_top HREF="' + urlresult + '">' + displayresult + "</a>");
}
</script>
<body bgcolor="white">
<object id=saOC CLASSID='clsid:B45FF030-4447-11D2-85DE-00C04FA35C89' HEIGHT=0 width=0></object>
<table width="400" cellpadding="3" cellspacing="5">
<tr>
<td id="tableProps" valign="top" align="left"><img id="pagerrorImg" SRC=http://www.okasp.com/techinfo/"pagerror.gif"
width="25" height="33"></td>
<td id="tableProps2" align="left" valign="middle" width="360"><h1 id="errortype"
style="COLOR: black; FONT: 12pt/15pt 新細明體"><span id="errorText"><b>找不到網頁</b></span></h1>
</td>
</tr>
<tr>
<td id="tablePropsWidth" width="400" colspan="2"><font
style="COLOR: black; FONT: 9pt/12pt 新細明體">查詢的網頁可能已經移除、變更名稱或者暫時無法使用。</font></td>
</tr>
<tr>
<td id="tablePropsWidth2" width="400" colspan="2"><font id="LID1"
style="COLOR: black; FONT: 9pt/12pt 新細明體"><hr color="#C0C0C0" noshade>
<p id="LID2">請嘗試下列:</p><ul>
<li id="list1">如果在網址列輸入網址,請確定未拼錯任何資料。<br>
</li>
<li id="list2">開啟 <script> Homepage(); </script> 首頁,然後查詢您想索取之資訊的連結。
</li>
<li id="list3">按<a href="
javascript:history.back(1)"><img valign=bottom border=0 src=http://www.okasp.com/techinfo/"back.gif"> [上一頁] </a>按鈕,移到其它連結。</li>
<li ID="list4">按一下<a onclick="saOC.NavigateToDefaultSearch();event.returnValue=false" href=""><img border=0 src=http://www.okasp.com/techinfo/"search.gif" width="16" height="16" alt=http://www.okasp.com/techinfo/"search.gif (114 位元組)" align="center"> [搜尋] </a>來尋找 Internet 資訊。 </li>
</ul>
<p><br>
</p>
<h2 id="ietext" style="font:9pt/12pt 新細明體; color:black">HTTP 404 - 找不到檔案<br>
Internet Explorer <BR>
</h2>
</font></td>
</tr>
</table>
</body>
</html>
一般未使用自定錯誤之前,你所應該看到的畫面應該如下圖所示
至於藍色那一段網址超連結的部分是透過404b.htm中Homepage()函數來解析所獲得的,要使用自己所定義的錯誤頁面有兩種方式可以完成,第一種是直接將自己所做的錯誤頁面存到C:\WINNT\help\common\404b.htm記得檔名要取一樣,第二個是將錯誤頁面儲存到你想存放的目錄之下,然後直接修改站台內容中自定錯誤選項中的錯誤頁面存放路徑,如下圖所示:
其中的http://www.yourserver.com/404.htm就是以URL為基準的存放路徑。
在IIS4.0中我們只能夠捕捉到404的錯誤訊息,但是IIS5.0卻能利用ASP程式捕捉伺服器應用程式500和100錯誤(在編譯或執行ASP程式時所發生的錯誤)的訊息,並在捕捉到訊息之後執行你想執行的ASP程式,譬如將使用者導向到某個網頁,這樣的方式讓使用者不必再忍受一但瀏覽網路時遭遇到錯誤而無所適從的困境,因為使用者多半不曉得發生什麼事,如果透過網站管理員告知使用者將會讓使用者覺得更貼心。
ASPERROR物件該如何使用呢?基本上他必須搭配SERVER物件的新方法GetLastError來使用,因為ASPERROR物件是透過Server.GetLastError方法來傳回錯誤訊息的。譬如說你將IIS5.0設定成當捕捉到伺服器應用程式500或100錯誤訊息之後將使用者導向到Error.asp,並利用Error.asp來描述所發生的錯誤,讓我們看看Error.asp在做些什麼事。
Error.asp
<%
Dim objLastASPError
'建立伺服器物件(取得ASP所產生的最後一項錯誤)
Set objLastASPError = Server.GetLastError
'描述錯誤情況
%>
伺服器遭遇如下的錯誤:<BR>
描述: <%=objLastASPError.Description%><BR>
錯誤類別: <%=objLastASPError.Category%><BR>
發生錯誤的檔案: <%=objLastASPError.File%><BR>
元件錯誤碼: <%=objLastASPError.Number%><BR>
基本上ASPError物件還有許多屬性,而這些屬性通通都是要靠建立伺服器物件,並以伺服器物件中的GetLastError方法來傳回錯誤訊息,讓我們看看ASPError物件還有哪些屬性:
ASPCODE:傳回IIS所產生的錯誤碼
NUMBER:傳回COM物件所產生的錯誤碼
SOURCE:傳回產生錯誤的那段原始程式
CATEGORY:如果是ASP內部產生錯誤,那會傳回是COM還是手稿語言的錯誤
FILE:傳回產生錯誤的ASP檔案名稱
LINE:指出是哪一行程式發生錯誤,傳回行數
DESCRIPTION:傳回簡短錯誤訊息
ASPDESCRIPTION:傳回詳細錯誤訊息
基本上這就是IIS5.0中的ASP3.0和IIS4.0中的ASP2.0所不同之處,當然啦,還有許多小地方也改了,只是比較不受人注意所以沒有寫出來,像IIS4.0中Response.Buffer的預設值是False,若使用者需要再將其開啟,但是IIS5.0為了提昇效能直接就將預設值設定為True,奇怪,既然能提昇效能為什麼IIS4.0要將他設定為False,打個電話去問比爾吧!!我也不知道。
关键词:WINDOWS 2000搭載ASP3.0与IIS5.0