I am attempting to catch all errors except '404-File not found' error in global.asax file and writing in to a text file in server,But lot of errors gets missed ,like FormatException Error,Sessionout Error and "Yellow Page of Error" Appears !
How can I catch all errors here.
void Application_Error(object sender, EventArgs e)
{
CT.Bussiness.DevCommonFunctions devTools = new CT.Bussiness.DevCommonFunctions();
HttpContext ctx = HttpContext.Current;
//ctx.Response.
// Get page url
if (ctx != null)
{
string pageName = ctx.Request.Url.ToString();
Exception ex = Server.GetLastError().GetBaseException();
HttpException checkException = (HttpException)ex;
if (checkException.GetHttpCode() != 404)
{
string errorDate = DateTime.Now.ToString();
//string pageName =pageName;
string errorMessage = ex.Message;
string errorSource = ex.Source;
//string errorInnerException=ex.InnerException.ToString();
string errorData = ex.Data.ToString();
string errorTarget = ex.TargetSite.ToString();
string errorStack = ex.StackTrace.ToString();
devTools.WriteErrorsIntoErrorLog(errorDate, pageName, errorMessage, errorSource, "InnerException", errorData, errorTarget, errorStack);
//devTools.SendErrorMail("developer3@devwebservices.net,developer4@devwebservices.net,developer5@devwebservices.net,hr@devwebservices.net", errorDate, pageName, errorMessage, errorSource, "InnerException", errorData, errorTarget, errorStack);
//Response.TrySkipIisCustomErrors = true;
Response.Redirect("~/Error.aspx");
//Response.Redirect("Error.aspx");
}
}
}
SOLVED
I Followed Like this as KPL Adviced below:
- Implemented Elmah
- Excluded Global.asax and
- Wrote redirection code in web.config.
Thus Solved !