protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.Master.PageTitle = "An Error Has Occurred"; this.lastError = Utilities.LastError; if (this.lastError == null) { this.lastError = new EDS.Intranet.Error.ErrorInfo(); this.lastError.Message = "No error found."; } }
protected override void OnError(EventArgs e) { try { //Retrieve the last error HttpContext ctx = HttpContext.Current; Exception exception = ctx.Server.GetLastError(); //Unpack the exception into an instance of the ErrorLog class EDS.Intranet.Error.ErrorInfo lastError = new EDS.Intranet.Error.ErrorInfo(); if (exception.InnerException == null) { lastError.Message = exception.Message; lastError.Source = exception.Source; lastError.StackTrace = exception.StackTrace; lastError.ExceptionType = exception.GetType().ToString(); if (exception.Data != null) { StringBuilder additionalInfo = new StringBuilder(); foreach (DictionaryEntry de in exception.Data) { additionalInfo.AppendLine(de.Key + " = " + de.Value + "<br/>"); } lastError.Data = additionalInfo.ToString(); } } else { lastError.Message = exception.InnerException.Message; lastError.Source = exception.InnerException.Source; lastError.StackTrace = exception.InnerException.StackTrace; lastError.ExceptionType = exception.InnerException.GetType().ToString(); if (exception.InnerException.Data != null) { StringBuilder additionalInfo = new StringBuilder(); foreach (DictionaryEntry de in exception.InnerException.Data) { additionalInfo.AppendLine(de.Key + " = " + de.Value + "<br/>"); } lastError.Data = additionalInfo.ToString(); } } if (exception.InnerException != null) { lastError.InnerException = Server.HtmlEncode(exception.InnerException.Message); } lastError.Exception = exception.Message; if (exception.GetBaseException() != null) { lastError.BaseException = exception.GetBaseException().Message; } lastError.BrowserType = ctx.Request.ServerVariables["HTTP_USER_AGENT"]; lastError.ComputerName = Utilities.GetComputerName(); lastError.NetVersion = Utilities.GetNetVersion(); lastError.OSVersion = Utilities.GetOSVersion(); if (exception.TargetSite != null) { lastError.Target = exception.TargetSite.Name; } lastError.Url = ctx.Request.Url.ToString(); lastError.UserID = this.LoginUserID; lastError.UserName = this.LoginUserName; //Encode any potentially problem text lastError.Message = Server.HtmlEncode(lastError.Message); //Save the error information into a static variable. Utilities.LastError = lastError; //Transfer to the GenericError page Response.Redirect("~/EDSIntranet/Error/GenericError.aspx", true); } catch { } }