日期:2013-01-14  浏览次数:21177 次

下面是根据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 =