using System; using System.Web; using Scrummer.Code.Pages; namespace Scrummer.Code { public static class GlobalErrorHandler { #region Private methods private static void ShowInternalError(HttpContext context, Exception ex) { context.Response.StatusCode = 500; context.Response.Clear(); context.Response.Write("
Message: {0}
", ex.Message)); context.Response.Write(String.Format("StackTrace:
{0}", ex.StackTrace));
// Fill response to 512 bytes to avoid browser "beauty" response of errors.
long fillResponse = 512 - (ex.Message.Length + ex.StackTrace.Length); ;
if (fillResponse > 0)
{
context.Response.Write("");
}
}
#endregion
#region Public methods
public static void HandleError(HttpContext context,Exception ex){
try
{
IHttpHandler frmError = new FrmError(ex);
context.Response.Clear();
context.Handler = frmError;
frmError.ProcessRequest(context);
}
catch
{
ShowInternalError(context, ex);
}
}
#endregion
}
}