1. Create a Global.asax file
2. Unified processing in Application_Error, can write to file, can also write to SQL. The code is as follows
Exception ex =Server.GetLastError (). GetBaseException (); StringBuilder SB=NewStringBuilder (); Sb. Appendline (DateTime.Now.ToString ("yyyy. MM.DD HH:mm:ss")); //there is a risk of being injected stringIP =""; if(Request.ServerVariables.Get ("http_x_forwarded_for") !=NULL) {IP= Request.ServerVariables.Get ("http_x_forwarded_for"). ToString (). Trim (); } Else{IP= Request.ServerVariables.Get ("REMOTE_ADDR"). ToString (). Trim (); } sb. Appendline ("IP Address:"+IP); Sb. Appendline ("Browser:"+Request.Browser.Browser.ToString ()); Sb. Appendline ("Browser version:"+Request.Browser.MajorVersion.ToString ()); Sb. Appendline ("Operating System:"+Request.Browser.Platform.ToString ()); Sb. Appendline ("error message:"); Sb. Appendline ("Request Address:"+Request.Url.ToString ()); Sb. Appendline ("error message:"+Ex. Message); Sb. Appendline ("Error Source:"+Ex. Source); Sb. Appendline ("Exception Method:"+Ex. TargetSite); Sb. Appendline ("Stack information:"+Ex. StackTrace); Sb. Appendline ("=========================================================================================================== ========="); stringLogFilePath = Server.MapPath ("~/log/"); if(!directory.exists (LogFilePath)) {directory.createdirectory (LogFilePath); } file.appendalltext (LogFilePath+ DateTime.Now.ToString ("yyyy. Mm.dd") +". Log", sb. ToString (), Encoding.UTF8); Server.ClearError (); Response.Redirect ("myerror.htm");
View Code
For injection problems can be seen
Http://www.cnblogs.com/kingthy/archive/2007/11/24/970783.html
Http://www.cnblogs.com/chengmo/archive/2013/05/29/php.html
ASP-processing error messages