Пример #1
0
 public bool ReportAbuse(string snippetId)
 {
     using (busCodeSnippet busSnippet = new busCodeSnippet())
     {
         if (busSnippet.Load(snippetId) == null)
         {
             throw new ArgumentException("Invalid snippetId passed.");
         }
         var snippet = busSnippet.Entity;
         // switch value
         snippet.IsAbuse = !snippet.IsAbuse;
         if (snippet.IsAbuse)
         {
             AppWebUtils.SendEmail("CodePaste.NET Abuse: " + busSnippet.Entity.Title, "Abuse reported for this snippet \r\n\r\n" + WebUtils.ResolveServerUrl("~/" + busSnippet.Entity.Id), App.Configuration.AdminEmailAddress);
         }
         if (!busSnippet.Save())
         {
             throw new ApplicationException(busSnippet.ErrorMessage);
         }
         return(snippet.IsAbuse);
     }
 }
Пример #2
0
        protected void Application_Error()
        {
            try
            {
                Exception serverException = Server.GetLastError();

                WebErrorHandler errorHandler;

                // Try to log the inner Exception since that's what
                // contains the 'real' error.
                if (serverException.InnerException != null)
                {
                    serverException = serverException.InnerException;
                }

                errorHandler = new WebErrorHandler(serverException);

                // MUST clear out any previous response in case error occurred in a view
                // that already started rendering
                Response.Clear();


                // Log the error if specified
                if (LogManagerConfiguration.Current.LogErrors)
                {
                    errorHandler.Parse();

                    //try
                    //{
                    WebLogEntry entry = new WebLogEntry(serverException, this.Context);
                    entry.Details = errorHandler.ToString();

                    LogManager.Current.WriteEntry(entry);
                    //}
                    //catch {  /* Log Error shouldn't kill the error handler */ }
                }

                // Retrieve the detailed String information of the Error
                string ErrorDetail = errorHandler.ToString();

                // Optionally email it to the Admin contacts set up in WebStoreConfig
                if (!string.IsNullOrEmpty(App.Configuration.ErrorEmailAddress))
                {
                    AppWebUtils.SendAdminEmail(App.Configuration.ApplicationTitle + "Error: " + Request.RawUrl, ErrorDetail, "",
                                               App.Configuration.ErrorEmailAddress);
                }


                // Debug modes handle different error display mechanisms
                // Default  - default ASP.Net - depends on web.config settings
                // Developer  - display a generic application error message with no error info
                // User  - display a detailed error message with full error info independent of web.config setting
                if (App.Configuration.DebugMode == DebugModes.DeveloperErrorMessage)
                {
                    Server.ClearError();
                    Response.TrySkipIisCustomErrors = true;
                    ErrorController.ShowErrorPage("Application Error", "<div class='codedisplay'><pre id='Code'>" + HttpUtility.HtmlEncode(ErrorDetail) + "</pre></div>");
                    return;
                }

                else if (App.Configuration.DebugMode == DebugModes.ApplicationErrorMessage)
                {
                    string StockMessage =
                        "The Server Administrator has been notified and the error logged.<p>" +
                        "Please continue by either clicking the back button or by returning to the home page.</p>" +
                        "<p><b><a href='" + Request.ApplicationPath + "'>Click here to continue...</a></b></p>";

                    // Handle some stock errors that may require special error pages
                    HttpException httpException = serverException as HttpException;
                    if (httpException != null)
                    {
                        int HttpCode = httpException.GetHttpCode();
                        Server.ClearError();

                        if (HttpCode == 404) // Page Not Found
                        {
                            Response.StatusCode = 404;
                            ErrorController.ShowErrorPage("Page not found",
                                                          "You've accessed an invalid page on this Web server. " +
                                                          StockMessage, null);
                            return;
                        }
                        if (HttpCode == 401) // Access Denied
                        {
                            Response.StatusCode = 401;
                            ErrorController.ShowErrorPage("Access Denied",
                                                          "You've accessed a resource that requires a valid login. " +
                                                          StockMessage);
                            return;
                        }
                    }

                    // Display a generic error message
                    Server.ClearError();
                    Response.StatusCode = 500;

                    Response.TrySkipIisCustomErrors = true;

                    ErrorController.ShowErrorPage("Application Error",
                                                  "We're sorry, but an unhandled error occurred on the server. " +
                                                  StockMessage);

                    return;
                }

                return;
            }
            catch (Exception ex)
            {
                // Failure in the attempt to report failure - try to email
                if (!string.IsNullOrEmpty(App.Configuration.ErrorEmailAddress))
                {
                    AppWebUtils.SendAdminEmail(App.Configuration.ApplicationTitle + "Error: " + Request.RawUrl,
                                               "Application_Error failed!\r\n\r\n" +
                                               ex.ToString(), "", App.Configuration.ErrorEmailAddress);
                }

                // and display an error message
                Server.ClearError();
                Response.StatusCode             = 500;
                Response.TrySkipIisCustomErrors = true;

                ErrorController.ShowErrorPage("Application Error Handler Failed",
                                              "The application Error Handler failed with an exception." +
                                              (App.Configuration.DebugMode == DebugModes.DeveloperErrorMessage ? "<pre>" + ex.ToString() + "</pre>" : ""), null);
            }
        }
Пример #3
0
 /// <summary>
 /// Sends email using the WebStoreConfig Email Configuration defaults.
 /// <seealso>Class WebUtils</seealso>
 /// </summary>
 /// <param name="Subject">
 /// The subject of the message.
 /// </param>
 /// <param name="Message">
 /// The body of the message.
 /// </param>
 /// <param name="Recipient">
 /// The recipient as an email address.
 /// </param>
 /// <param name="Boolean SendAsText">
 /// Determines whether the message is sent as Text or HTML.
 /// </param>
 /// <returns>Boolean</returns>
 public static bool SendEmail(string Subject, string Message, string Recipient, bool SendAsText)
 {
     return(AppWebUtils.SendEmail(Subject, Message, Recipient, null, null, false, SendAsText, null));
 }