自定义错误页面

2.建立一个页面类(假设叫BasePage),继承于Page,然后你的站点的所有页面都从这个类继承,这样你只要在BasePage类里:override OnInit事件,在里面:
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();
		}
原文地址:https://www.cnblogs.com/King0502/p/2019417.html