void Application_Error(object sender, EventArgs e) { Try { // Code that runs when an unhandled error occurs // Get the error details HttpContext CurrentHTTPcontext = HttpContext.Current; HttpException lastErrorWrapper = Server.GetLastError() as HttpException; Exception lastError = lastErrorWrapper; if (lastErrorWrapper.InnerException != null) lastError = lastErrorWrapper.InnerException; string ErrorPageURL = CurrentHTTPcontext.Request.Url.ToString(); string ErrorMessage = lastError.Message; string ErrorStackTrace = lastError.StackTrace; MainFunction mainfun = new MainFunction(); SqlConnection sqlcon = new SqlConnection(ConfigurationSettings.AppSettings["CON"]); Try { SqlCommand sqlcmd = new SqlCommand(); sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.Connection = sqlcon; sqlcmd.Parameters.Add(new SqlParameter("@PageURL", SqlDbType.VarChar, 500)).Value = Server.HtmlEncode(ErrorPageURL); sqlcmd.Parameters.Add(new SqlParameter("@ErrorMessage", SqlDbType.VarChar, 2000)).Value = Server.HtmlEncode(ErrorMessage); sqlcmd.Parameters.Add(new SqlParameter("@ErrorStackTrace", SqlDbType.Text)).Value = Server.HtmlEncode(ErrorStackTrace); sqlcmd.CommandText = "Sp__ErrorLog"; // Procedure Name if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } sqlcmd.ExecuteNonQuery(); if (sqlcon.State == ConnectionState.Open) { sqlcon.Close(); } } catch { if (sqlcon.State == ConnectionState.Open) { sqlcon.Close(); } } } catch { } }
R D Patel
Login to post response