|
using System;
using System.Web;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Web.UI;
using Microsoft.Practices.EnterpriseLibrary.Logging;
namespace CentralErrorHandler
{
public class ErrorModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
//throw new Exception("The method or operation is not implemented.");
}
public void Init(HttpApplication Context)
{
Context.Error += new EventHandler(Application_Error);
}
#endregion
public void Application_Error(object sender, EventArgs e)
{
HttpContext Context = HttpContext.Current;
Exception exception;
for (exception = Context.Server.GetLastError(); exception.InnerException != null; exception = exception.InnerException) { }
String code = DateTime.Now.ToString("ddMMyyyy-HHmmfff");
String Message = exception.Message + Environment.NewLine + "Stack Trace: " + exception.StackTrace;
Logger.Write(Message, "General",5, 1, System.Diagnostics.TraceEventType.Critical, code);
HttpContext.Current.Application.Add("ErrorCode", code);
HttpContext.Current.Application.Add("LastException", exception);
String CustomErrorPagePath = System.Configuration.ConfigurationManager.AppSettings["CustomErrorPagePath"];
((System.Web.HttpApplication)(sender)).Response.Redirect(CustomErrorPagePath);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Expertise area: ASP.NET, C#, Microsoft Office SharePoint 2010 & 2007, Web Service, Windows-based Applications etc.
Blog: http://mydevdiary.blogspot.com/