Error(Objectsender,EventArgse){
if(Server.GetLastError()isHttpUnhandledException)
Server.Transfer("MyErrorPage.aspx");
//其余的非HttpUnhandledException异常交给ASP.
NET自己处理就okay了:)
}
Redirect会导致post-back的产生从而丢失了错误信息,所以页面导向应该直接在服务器端执行,这样就可以在错误处理页面得到出错信息并进行相应的处理
10.清空Cookie
Cookie.Expires=[DateTime];
Response.Cookies("UserName").Expires=0
11.自定义异常处理
//自定义异常处理类
usingSystem;
usingSystem.Diagnostics;
namespaceMyAppException
{
///<summary>
///从
系统异常类ApplicationException继承的应用
程序异常处理类。
///自动将异常内容记录到WindowsNT/2000的应用程序日志
///</summary>
publicclassAppException:System.ApplicationException
{
publicAppException()
{
if(ApplicationConfiguration.EventLogEnabled)LogEvent("出现一个未知错误。");
}
publicAppException(stringmessage)
{
LogEvent(message);
}
publicAppException(stringmessage,ExceptioninnerException)
{
LogEvent(message);
if(innerException!=null)
{
LogEvent(innerException.Message);
}
}
//日志记录类
usingSystem;
usingSystem.Configuration;
usingSystem.Diagnostics;
usingSystem.IO;
usingSystem.Text;
usingSystem.Threading;
namespaceMyEventLog
{
///<summary>
///事件日志记录类,提供事件日志记录支持
///<remarks>
///定义了4个日志记录方法(error,warning,info,trace)
///</remarks>
///</summary>
publicclassApplicationLog
{
///<summary>
///将错误信息记录到Win2000/NT事件日志中
///<paramname="message">需要记录的文本信息</param>
///</summary>
publicstaticvoidWriteError(Stringmessage)
{
WriteLog(TraceLevel.Error,mess