1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| void Application_Error(object sender, EventArgs e)
{
HttpContext context = ((HttpApplication)sender).Context;
Exception ex = context.Server.GetLastError();
if (ex == null || !(ex is HttpException) || (ex as HttpException).GetHttpCode() == 404)
return;
StringBuilder sb = new StringBuilder();
try
{
sb.Append("Url : " + context.Request.Url);
sb.Append(Environment.NewLine);
sb.Append("Raw Url : " + context.Request.RawUrl);
sb.Append(Environment.NewLine);
while (ex != null)
{
sb.Append("Message : " + ex.Message);
sb.Append(Environment.NewLine);
sb.Append("Source : " + ex.Source);
sb.Append(Environment.NewLine);
sb.Append("StackTrace : " + ex.StackTrace);
sb.Append(Environment.NewLine);
sb.Append("TargetSite : " + ex.TargetSite);
sb.Append(Environment.NewLine);
ex = ex.InnerException;
}
}
catch (Exception ex2)
{
sb.Append("Error logging error : " + ex2.Message);
}
//ENVOI PAR MAIL, OU ENREGISTREMENT DANS UN LOG
context.Items["LastErrorDetails"] = sb.ToString();
context.Response.StatusCode = 500;
Server.ClearError();
// Server.Transfer is prohibited during a page callback.
System.Web.UI.Page currentPage = context.CurrentHandler as System.Web.UI.Page;
if (currentPage != null && currentPage.IsCallback)
return;
context.Server.Transfer("~/error.aspx");
} |
Partager