答案:下面是根据wrox的professional asp 3.0建立的网站错误检查机制,使用了之后,你可以找到自己很多的错误,节省大量的代码测试时间,为什么不用呢!
首先建立表:
CREATE TABLE [dbo].[tSiteErrors] (
[kErrKey] [int] IDENTITY (1, 1) NOT NULL ,
[dDatetime] [datetime] NOT NULL ,
[ErrorType] [varchar] (255) NOT NULL ,
[TargetUrl] [varchar] (255) NULL ,
[ErrorInfo] [varchar] (255) NULL
) ON [PRIMARY]
GO
一、检查记录网站的错误链接:
在网站的目录中建立/siteerror/naverror.asp
________________________________________________
<%@LANGUAGE="VBScript"%>
<%Response.Status = "404 Not Found" %>
<!--这里是数据库连接字符串的位置-->
<!--#include file="../include/connect.asp"-->
<html>
<head>
<title>无法找到网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="robots" content="noindex">
<style type="text/css">
<!--
td { font-size: 9pt}
a{color:#000000;text-decoration:none;}
A:link {COLOR: #000000; TEXT-DECORATION: none}
A:visited {COLOR: #000000; TEXT-DECORATION: none}
A:active {COLOR: #000000; TEXT-DECORATION: none}
A:hover {COLOR: #0C78D1; TEXT-DECORATION: underline}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0">
<table width="100%" border="1" cellspacing="0" cellpadding="0" height="95%" bordercolor="#000000" align="center">
<tr>
<td bgcolor="#FFFFFF">
<h2><b><font color="#993399"> 无法找到网页</font></b></h2>
<hr>
<b><font color="#999999"> 您正在搜索的网页可能已经删除、更名或暂时不可用。</font></b>
<%
'On Error Resume Next
strTarget = Request.ServerVariables("QUERY_STRING")
strReferer = Request.ServerVariables("HTTP_REFERER")
intSemiColon = InStr(strTarget, ";") 'get the original target
If (intSemiColon > 0) And (intSemiColon < Len(strTarget)) Then
strTarget = Mid(strTarget, intSemiColon + 1)
If Len(strTarget) > 254 Then strTarget = Left(strTarget, 254)
End If
If Len(strReferer) > 255 Then strReferer = Left(strReferer, 255)
strInform = "<font style=""COLOR:000000; FONT: 9pt/11pt 宋体"">请通知包含该错误链接的网站管理员。</font>"
strTyping = "<font style=""COLOR:000000; FONT: 9pt/11pt 宋体""> 如果您在“地址”栏中键入了网页地址,请检查其拼写是否正确。或者:</font>"
strRecord = "<font style=""COLOR:000000; FONT: 9pt/11pt 宋体"">这个错误已经被记录,将尽快得到处理。</a>"
Response.Write "<p> 无法找到的网页地址为: " & strTarget & "<P>"
If Len(strReferer) > 0 Then 'came from a link on another page
Response.Write "<font style=""COLOR:000000; FONT: 9pt/11pt 宋体"">下列网页中发现了链接错误: " & strReferer _
& " 。</font><BR>"
Set oConn = Server.CreateObject("ADODB.Connection") 'to store the details
oConn.Open dsn
strsql="exec sp_errorrecorder 'broken link','" & strtarget & "','"&strReferer&"'"
oConn.Execute strSQL
Rem 注意这里
If Err.Number = 0 And InStr(strReferer, "你的域名 例如163.com") > 0 Then
Response.Write strRecord 'came from a page on our site
Else
Response.Write strInform 'came from a page on another site
End If
Else
Response.Write strTyping 'they just typed it wrong into their browser
End If
%>
<!--这里的连接是你的域名-->
<p> <a href=> </p>
<p> 单击<a href=> <hr>
<p> <a href=> </p>
<p> </p>
<p> </p>
</td>
</tr>
<tr>
<td height="5" bgcolor="#000000"></td>
</tr>
</table>
</body>
</html>
二、检查记录网站的代码错误:
在网站的目录中建立/siteerror/asperror.asp
<%@Language="vbscript"%>
<% Response.Status="500 Internal Error"%>
<!--#include file=../include/connect.asp-->
<html>
<head>
<meta name="robots" content="noindex">
<title>服务器内部错误</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
td { font-size: 9pt}
a{color:#000000;text-decoration:none;}
A:link {COLOR: #000000; TEXT-DECORATION: none}
A:visited {COLOR: #000000; TEXT-DECORATION: none}
A:active {COLOR: #000000; TEXT-DECORATION: none}
A:hover {COLOR: #0C78D1; TEXT-DECORATION: underline}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" topmargin="0">
<%
response.flush
On error resume next
set objAspError=Server.GetLastError()
strErrNumber=CStr(objAspError.Number)
strASPCode=objAspError.aspcode
strErrDescription=objAspError.Description
strASpdescription=objAspError.aspdescription
strcategory=objAspError.category
strfilename=objAspError.file
strlinenum=objAspError.line
strcolnum=objAspError.column
if isnumeric(strcolnum) then
lngcolnum=clng(strcolnum)
else
lngcolnum=0
end if
strsourcecode=objasperror.source
set objasperror=nothing
if len(strfilename) then
strtarget=strfilename
else
strtarget="**File name not available **"
end if
if len(straspcode) then
strInfo="'" & straspcode & "'"
else
strinfo="Error"
end if
if len(strCategory) then
strInfo=strinfo & " in " & strcategory & ".<br>"
end if
strInfo=strinfo & "Code: " & strErrNumber & "(0x" & hex(strErrnumber)
上一个:在 Flash 中使用 ASP 操控 Cookies
下一个:ASP+JS时的