Beispiel #1
0
        private bool DisplayDetailedError()
        {
            Trace.Write("myErrorPage.aspx", "Display Detailed Error");

            // The error is stored with whatever method is specific in web.config in the tag:
            // <add key="customErrorMethod" value="application/context/cookie/querystring/off" />
            IErrorIOHandler objErrorBasket = ErrorIOFactory.Create(ConfigurationSettings.AppSettings["customErrorMethod"]);
            ErrorStorage    st             = objErrorBasket.Retrieve();

            // Whatever the method used, always clear it when done.
            objErrorBasket.Clear();

            string pattern = "<H2 style='FONT-SIZE: 14pt; COLOR: red'>{0}</H2>{1}";

            if (st.Type == typeof(NeJudgeSecurityException).FullName)
            {
                panelDetailedError.Visible = false;
                mesLiteral.Text            = String.Format(pattern, @"Недостаточно прав.",
                                                           "Вы не обладаете правами группы " + st.Message); //+"\r\n"+"Ваши права: "+groups;
            }
            else if (st.Type == typeof(NeJudgeInvalidParametersException).FullName)
            {
                panelDetailedError.Visible = false;
                mesLiteral.Text            = String.Format(pattern, @"Были указаны неверные параметры.",
                                                           @"В качестве параметра " + st.Message + @" было передано неверное значение.");
            }
            else
            {
                st.StackTrace      = Regex.Replace(st.StackTrace, "\n", "<br />");
                litMessage.Text    = st.Message;
                litSource.Text     = st.Source;
                litStackTrace.Text = st.StackTrace;
                litErrorDate.Text  = st.Date;
                litErrorType.Text  = st.Type;
            }
            return(true);
        }
Beispiel #2
0
        //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Assert, Name="FullTrust")]
        protected void Application_Error(Object sender, EventArgs e)
        {
            HttpContext.Current.Trace.Write("global.asax: Application_Error");

            Exception objError = Server.GetLastError().GetBaseException();

            // Write to Event Log based on web.config setting:
            // <add key="customErrorAutomaticLogging" value="on/off" />
            if (ConfigurationSettings.AppSettings["customErrorAutomaticLogging"].ToLower() == "on")
            {
                WriteErrorToLog(objError);
            }

            // Automatic E-mail Notification based on web.config setting:
            // <add key="customErrorAutomaticEmail" value="on/off" />
            // <add key="customErrorAutomaticEmailAddress" value="[address goes here]" />
            if (ConfigurationSettings.AppSettings["customErrorAutomaticEmail"].ToLower() == "on")
            {
                EmailError(objError, ConfigurationSettings.AppSettings["customErrorEmailAddress"]);
            }

            // If customErrorMethod isn't off or unset, then store the exception
            // web.config:appSettings:customErrorMethod follows this syntax:
            // <add key="customErrorMethod" value="application/cookie/context/querystring/off" />
            string strErrorMethod = ConfigurationSettings.AppSettings["customErrorMethod"].ToLower();

            if (strErrorMethod != "off" && strErrorMethod != "")
            {
                // Make an exception storage basket as specified by web.config setting:
                // <add key="customErrorMethod" value="application/cookie/context/querystring/off" />
                IErrorIOHandler objErrorBasket = ErrorIOFactory.Create(strErrorMethod);

                // Store the exception in the basket while generating the path to the custom error page.
                string strRedirect    = ConfigurationSettings.AppSettings["customErrorPage"];
                string strQueryString = objErrorBasket.Store(objError);
                string strFilePath    = strRedirect + strQueryString;

                if (strRedirect != "")
                {
                    switch (ConfigurationSettings.AppSettings["customErrorBranchMethod"].ToLower())
                    {
                    case "transfer":
                        // Use with application, context, or cookie. Results in originally requested URL.
                        Server.Transfer(strFilePath, false);
                        break;

                    case "redirect":
                        // Use with application, cookie, or querystring. Results in the custom error page's URL.
                        Response.Redirect(strFilePath);
                        break;
                    }
                }
            }

            /*StringBuilder message = new StringBuilder();
             * if (Server != null)
             * {
             *      Exception ex;
             *      for (ex = Server.GetLastError(); ex != null; ex = ex.InnerException)
             *      {
             *              message.AppendFormat("{0}: {1}{2}\r\n",
             *                      ex.GetType().FullName,
             *                      ex.Message,
             *                      ex.StackTrace);
             *      }
             *      EventLog.WriteEntry("NeJudge",message.ToString(),EventLogEntryType.Error);
             * }*/
        }