一个关于APPLICATION——ERROR的例子

程序会在当前目录生成一个ERROR的目录,这个文件还有待于更新

<%@ Import Namespace="System.IO"%>
<%@ import namespace="system.data"%>
<%@ import namespace="System.Configuration"%>
<%@ import namespace="system.Collections"%>
<%@ import namespace="system.ComponentModel"%>
<%@ import namespace="system.net"%>
<%--
    文件名:golbal.asax
 文件用途:用于记录本日志及站内在线人数的统计
    建立时间:2005-12-23
 位于服务器目录:/global.asax
 文件说明:可能将来还会用来做虚拟网址
 文件大小:
--%>
<Script language="VB" runat="server">

    sub Application_BeginRequest(sender as object,e as eventargs)
         Response.Write("当前访问的页面是 "& Request.FilePath &"<br>")
    end sub

  sub Application_Error(sender as Object ,e as EventArgs )
 

      dim str_username as string
      if request.Cookies("b2b_iscookie") is nothing then
         str_username="游客"
      else
         str_username="-"
      end if
  
      if directory.exists(Request.PhysicalApplicationPath()  &"error_log")=false then
         directory.CreateDirectory(Request.PhysicalApplicationPath() &"error_log")
   end if

      dim sw as streamwriter
    
      if file.exists(request.physicalapplicationPath &"error_log/error.log")=false then
         sw = File.CreateText(Request.PhysicalApplicationPath &"error_log/error.log")
   else
         sw = File.AppendText(Request.PhysicalApplicationPath &"error_log/error.log")
   end if
     

      SW.WriteLine(DateTime.Now() & vbcrlf &"出错的用户:"& str_username & vbcrlf &"用户IP:"& Request.UserHostAddress & vbcrlf &"出错的页面:"& Request.Path &"?"& Request.QueryString.tostring & vbcrlf &"错误类型:"& Server.GetLastError().Message.tostring() & vbcrlf &"错误信息:"& Server.GetLastError().InnerException.tostring() & vbcrlf &"****************************************************************************************" & vbcrlf & vbcrlf)
      SW.Close()
      err.clear()
 end sub

 

</script>
以前文件,是我自己用的,删除部分敏感的语句

posted @ 2006-07-10 13:42  盗马人  阅读(291)  评论(0)    收藏  举报