Global.asax文件中加入
/// <summary>
/// 系统错误日志记录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Error(Object sender, EventArgs e)
{
//错误的全局处理
Exception ex = Server.GetLastError().GetBaseException() ;
/// 系统错误日志记录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Error(Object sender, EventArgs e)
{
//错误的全局处理
Exception ex = Server.GetLastError().GetBaseException() ;
//记录错误日志
string strFile = Request.ApplicationPath + "/sys_error.log";
strFile = Server.MapPath(strFile);
System.IO.StreamWriter st = new System.IO.StreamWriter (strFile,true,System.Text.Encoding.UTF8);
string sText ="" ;
sText += "/r/n//----------------------------------------------------------------------------/r/n";
sText += "//----------------------------------------------------------------------------/r/n";
sText += "系统出现如下错误:/r/n";
sText += " 发生时间 : " + DateTime.Now.ToString() + "/r/n";
sText += " 错误描述 : " + ex.Message.Replace("/r/n","") + "/r/n";
sText += " 错误对象 : " + ex.Source + "/r/n";
sText += " 错误帮助 : " + ex.HelpLink + "/r/n";
sText += " 错误页面 : " + Request.UrlReferrer + "/r/n";
sText += " 用户 IP : " + Request.UserHostAddress + "/r/n";
sText += " 用户 IE : " + Request.UserAgent + "/r/n";
sText += " 详细描述 :/r/n" + ex.StackTrace + "/r/n";
sText += "/r/n";
string strFile = Request.ApplicationPath + "/sys_error.log";
strFile = Server.MapPath(strFile);
System.IO.StreamWriter st = new System.IO.StreamWriter (strFile,true,System.Text.Encoding.UTF8);
string sText ="" ;
sText += "/r/n//----------------------------------------------------------------------------/r/n";
sText += "//----------------------------------------------------------------------------/r/n";
sText += "系统出现如下错误:/r/n";
sText += " 发生时间 : " + DateTime.Now.ToString() + "/r/n";
sText += " 错误描述 : " + ex.Message.Replace("/r/n","") + "/r/n";
sText += " 错误对象 : " + ex.Source + "/r/n";
sText += " 错误帮助 : " + ex.HelpLink + "/r/n";
sText += " 错误页面 : " + Request.UrlReferrer + "/r/n";
sText += " 用户 IP : " + Request.UserHostAddress + "/r/n";
sText += " 用户 IE : " + Request.UserAgent + "/r/n";
sText += " 详细描述 :/r/n" + ex.StackTrace + "/r/n";
sText += "/r/n";
st.Write(sText);
st.Close();
st.Close();
Response.Write ("<script language='javascript'>alert(/"错误描述:" + ex.Message.Replace("/r/n","") + "
//n//n错误对象:" + ex.Source.Replace("/n","") + "/");");
Response.Write ("history.go(-1);");
Response.Write ("</script>");
Response.End();
}
Response.Write ("history.go(-1);");
Response.Write ("</script>");
Response.End();
}