Ejemplo n.º 1
0
        private void Application_Error( object sender, EventArgs e )
        {
            //https://msdn.microsoft.com/en-us/library/24395wz3.aspx

            HttpServerUtility server = HttpContext.Current.Server;
            Exception exception = server.GetLastError();
            string currentPageRequest = HttpContext.Current.Request.FilePath;


            if (Configuration.Development.GetIsEnabledDebugDeveloperModeShowGlobalPageError())
            {

                if (exception.GetType() == typeof( HttpException ))
                {
                    Server.Transfer( "~/ErrorPageHttp.aspx" );
                }
                else
                {
                    Response.Write( "<h2>Global Page Error</h2>\n" );
                    Response.Write(
                        "<p>" + exception.Message + "</p>\n" );
                    Response.Write( "Return to the <a href='/Default.aspx'>" +
                        "Default Page</a>\n" );

                    if (Context.Request.IsLocal)
                    {
                        Response.Write( "<p>" + exception.Source + "</p>\n" );
                        Response.Write( "<p>" + exception.InnerException + "</p>\n" );
                        Response.Write( "<p>" + exception.StackTrace + "</p>\n" );
                    }
                }

                if (! _previousPageError.Equals( currentPageRequest ))
                {

                    ExceptionUtility.LogException( exception, currentPageRequest );
                    ExceptionUtility.NotifySystemOps( exception );
                }
            }

            // if not in DEV MODE, write error to .txt
            if (!Configuration.Development.GetIsEnabledDeveloperMode())
            {


                // devexpress callback error
                // Use HttpContext.Current to get a Web request processing helper

                // is http?
                if (exception is HttpUnhandledException)
                {



                    HttpException ex = (HttpException)Server.GetLastError();
                    //Exception innerexception = exception.InnerException;

                    // Log an exception
                    // TODO, send email to admin.
                    if (!_previousPageError.Equals( currentPageRequest ))
                    {

                        ExceptionUtility.LogException( exception, currentPageRequest );
                        ExceptionUtility.NotifySystemOps( exception );


                        // log to logger
                        if (HttpContext.Current != null && HttpContext.Current.Request != null)
                            Global.LogError( Context, Global.EnumLogCategories.GENERAL,
                            "HTTP " + ex.GetHttpCode() + ": " + Request.RawUrl.ToString(),
                            ex );
                    }

                    // options to show info to user:
                    // 1. show a blank page:
                    //Server.ClearError();
                    // 2. redirect to a page
                    // Response.Redirect("~/Errors/ErrorPageHttp.aspx");
                    // 3. do nothing, go to customErrors configuration in web.config and/or show asp.net error
                }
                else
                {
                    // other NO http errors
                    ExceptionUtility.LogException( exception, currentPageRequest );
                    ExceptionUtility.NotifySystemOps( exception );

                    // log to logger
                    if (HttpContext.Current != null && HttpContext.Current.Request != null)
                        Global.LogError( Context, Global.EnumLogCategories.GENERAL,
                        "Error " + exception.HResult + ": " + Request.RawUrl.ToString(),
                        exception );

                }

            }
            else
            {
                ExceptionUtility.LogException( exception, currentPageRequest );
                ExceptionUtility.NotifySystemOps( exception );

                // log to logger, no works in callback mode
                /*
                if (HttpContext.Current != null && HttpContext.Current.Request != null)
                    Global.LogError( Context, Global.EnumLogCategories.GENERAL,
                        "Error " + exception.HResult + ": " + Request.RawUrl.ToString(),
                        exception );
                        */

                ExceptionUtility.LogException( exception, currentPageRequest );
                ExceptionUtility.NotifySystemOps( exception );



            }

            

            //_previousException = exception;
            _previousPageError = currentPageRequest;


        }