this.Error += new System.EventHandler(this.error());
然后在error()方法里做你的统一的错误处理,这样,所有页的错误处理就一样了。
| ? | 给你点例子:
protected void error(object sender, System.EventArgs e)
{
string errMsg;
Exception currentError = Server.GetLastError();
errMsg = "<h1>Page Error</h1><hr/>An unexpected error has occurred on this page. The system " +"administrators have been notified. Please feel free to contact us with the information " +"surrounding this error.<br/>"+
"The error occurred in: "+Request.Url.ToString()+"<br/>"+
"Error Message: <font class=\"ErrorMessage\">"+ currentError.Message.ToString() + "</font><hr/>"+
"<b>Stack Trace:</b><br/>"+
currentError.ToString();
if ( !(currentError is AppException) )
{
// It is not one of ours, so we cannot guarantee that it has been logged
// into the event log.
LogEvent( currentError.ToString(), EventLogEntryType.Error );
}
Response.Write( errMsg );
Server.ClearError();
}
| ||